Skip to content

Instantly share code, notes, and snippets.

@coopernurse
Created August 26, 2011 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coopernurse/1174475 to your computer and use it in GitHub Desktop.
Save coopernurse/1174475 to your computer and use it in GitHub Desktop.
attempt at noir middleware that uses (binding)
(ns votenoir.requtil)
(def *request*)
(defn absolute-url
"Converts uri into a full URL based on the current request
For example, given a current request URL of:
http://example.com:9000/foo/bar
Deployed as foo.war (so /foo is the servlet context path)
Then: (absolute-url \"/baz\") returns: http://example.com:9000/foo/baz"
([uri]
(let [req (:request *request*)]
(absolute-url (.getScheme req) (.getServerName req) (.getServerPort req) (.getContextPath req) uri)))
([scheme host port context uri]
(str scheme "://" host (if (or (= 80 port) (= 443 port)) "" (str ":" port)) context uri)))
(defn wrap-requtil
[handler]
(fn [request]
(binding [*request* request]
(handler request))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment