Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 23 lines (19 sloc) 0.82 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
(ns foreclojure.ring-utils
  (:require [foreclojure.config :as config]))

(def ^{:dynamic true} *url* nil) ; url of current request
(def ^{:dynamic true} *host* nil) ; Host header sent by client
(def ^{:dynamic true} *http-scheme* nil) ; keyword, :http or :https

(defn get-host [request]
  (get-in request [:headers "host"]))

(defn wrap-request-bindings [handler]
  (fn [req]
    (binding [*url* (:uri req)
              *host* (or (get-host req) config/canonical-host)
              *http-scheme* (:scheme req)]
      (handler req))))

(letfn [(url-fn [host]
          (if host
            #(str (name (or *http-scheme* :http)) "://" host "/" %)
            #(str "/" %)))]
  (def universal-url (url-fn (or config/static-host config/canonical-host)))
  (def static-url (url-fn config/static-host)))
Something went wrong with that request. Please try again.