Last active
December 16, 2015 21:49
-
-
Save sw1nn/5502950 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn follow-redirect | |
[client {:keys [uri url scheme server-name server-port] :as req} | |
{:keys [trace-redirects] :as resp}] | |
(let [url (or url (str (name scheme) "://" server-name | |
(when server-port (str ":" server-port)) | |
uri)) | |
raw-redirect (get-in resp [:headers "location"]) | |
redirect (str (URL. (URL. url) raw-redirect))] | |
((wrap-redirects client) (-> req | |
(merge (parse-url redirect)) | |
(dissoc :query-params) | |
(assoc :url redirect | |
:trace-redirects trace-redirects))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
added in line 11 basically, but this might conflict with with custom middleware that does something 'funky'. I think correct behaviour is to remove the inconsistent parsed bits