Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Dealing with redirects across schemes in Ring
[ring.util.response :as res]))
; This is the code I've currently got doing redirects between http and https
(def port-override {})
(def standard-ports {:http 80 :https 443})
(defn set-override [scheme port]
(if-not (= port (standard-ports scheme))
(alter-var-root #'port-override assoc scheme port)))
(defn url [{:keys [scheme server-name] :as request} url requested-scheme]
(if (= scheme requested-scheme)
(let [port (port-override requested-scheme)]
(str (name requestedScheme)
"://" server-name (if port (str ":" port)) url))))
(defn redirect [request destination scheme]
(res/redirect (url request destination :https)))
(defn report-ports [http https]
(println (str "Ports reported " http "," https))
(set-override :http http)
(set-override :https https))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment