Welcome! Please see the About page for a little more info on how this works.

+1 vote
in Libs by

Hi! I'm having a problem doing a redirection with Ring. If I'm on a page with the POST method, doing the redirection will keep it. How can I force all my redirections to be GET? Thank you in advance.

1 Answer

+2 votes
selected by
Best answer

You'll need to share at least some of the code that doesn't work.

We use ring.util.response/redirect all the time at work to redirect from handlers that process POST requests to new URLs that are GETs -- that's pretty much the definition of how a redirect works since it produces a Location: header which the browser then uses to GET the specified URL.

edited by
You're right, it works using ring redirect,


but if I use the status 307 I redirect with POST

(-> (response/redirect url)
       (assoc :session (-> req :session))
       (assoc :status 307))

Shouldn't it work?
I'm not sure what you're asking, sorry.

Status 307 should tell the browser to use the same HTTP method again on the new location URL (so if POST /url1 yields Location /url2 with Status 307, the browser should do POST /url2).

If you want the redirections to be GET, do not use status 307.
I'm already answered. Thanks for the help!
Welcome to Clojure Q&A, where you can ask questions and receive answers from members of the Clojure community.