forked from 4clojure/4clojure
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathring_utils.clj
More file actions
23 lines (19 loc) · 820 Bytes
/
Copy pathring_utils.clj
File metadata and controls
23 lines (19 loc) · 820 Bytes
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)))