 (import '(javax.servlet.http HttpServlet
                              HttpServletRequest
                              HttpServletResponse))
+
+;;;; General-purpose functions ;;;;
+
 (defn includes?
   "Returns true if x is contained in coll, else false."
   [x coll]

  (or (. context (getMimeType filename))
      *default-mimetype*))

(defn re-escape
  "Escape all special regex chars in a string s."
  [s]
  (escape "\\.*+|?()[]{}$^" s))

(def symbol-regex (re-pattern ":([a-z_]+)"))

(defn re-find-all
  "Repeat re-find for matcher m until nil, and return the seq of results."
  [m]
  (doall (take-while identity
    (map re-find (repeat m)))))

(defn parse-route
  "Turn a route string into a regex and seq of symbols."


(defmacro GET "Creates a GET resource."
  [route & body]
  `(assoc-route "GET" ~route (resource ~@body)))

(defmacro PUT "Creates a PUT resource."
  [route & body]
  `(assoc-route "POST" ~route (resource ~@body)))

(defmacro POST "Creates a POST resource."
  [route & body]
  `(assoc-route "PUT" ~route (resource ~@body)))

(defmacro DELETE "Creates a DELETE resource."
  [route & body]
  `(assoc-route "DELETE" ~route (resource ~@body)))

;;;; Servlet

(def #^{:doc 
  "A servlet that handles all requests into Compojure. Suitable for
