Skip to content

Instantly share code, notes, and snippets.

@sw1nn
Last active December 16, 2015 21:49
Show Gist options
  • Save sw1nn/5502950 to your computer and use it in GitHub Desktop.
Save sw1nn/5502950 to your computer and use it in GitHub Desktop.
(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)))))
@sw1nn
Copy link
Author

sw1nn commented May 2, 2013

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment