Redirect To "verb" issue

Weird issue with redirect(conn, to). App calls redirect to reload index page after deleted an entity. But redirect is trying to use DELETE instead of GET. Conn doesn’t contain any “delete” - I tried to change :phoenix_action and :method conn’s parameters to GET. Is it possible to explicitly assign GET to redirect to index or maybe any idea where it sets DELETE?

Congratulations, you are using an HTTP confirming user agent and a webserver which relies on a faulty implementation of 302 handling.

Note: RFC 1945 and RFC 2068 specify that the client is not allowed
to change the method on the redirected request. However, most
existing user agent implementations treat 302 as if it were a 303
response, performing a GET on the Location field-value regardless
of the original request method. The status codes 303 and 307 have
been added for servers that wish to make unambiguously clear which
kind of reaction is expected of the client.

Please Plug.Conn.put_status/2 the appropriate of 303 or 307 and then use Phoenix.Controller.redirect/2, it will leave a previously put status untouched. 302 is only used iff there was non set earlier.

2 Likes

Thank you!. 303 works, 307 doesn’t. But not exactly as it should. App is calling index than, I can see that by reloading data from database, but browser doesn’t reload a page. Is it possible somehow to ping browser and update page?

307 is meant to keep original method as 302 was meant intentionally. According to the standard a client is not allowed to follow a 307 that is not GET or HEAD without asking the user for a permission to do so. Since you do not want to keep the old method, 307 isn’t what you want.

303 on the other hand side, is meant for exactly what we want. Issue a request with any method, handle the request, including sideeffects and then redirect to a “safe url” with a “safe method” which is sideeffect free.

And, can you please tell us what browser you are using? Have you already tried a different one?

Thanks for a great explanation!
I have tried with safari and chrome. Both of them doesn’t reload a page and no flash message.

Funny. I never had any problems using Chrome on phoenix. It always did a GET after I used redirect/2. Can you provide a minimal project which shows that behaviour. Perhaps we can use the “crowd” to check the behaviour in multiple browsers and versions.

Perhaps this makes us even able to file a bug at phoenix.

having a particular issue with the redirect/2
anytime i redirect the page just shows you are being redirected…
any help?

Having same problem as @thomasdola. Sometimes when a redirect is issued, the page remains stuck in loading, not sure why. I’m sort of new to Elixir, so at first I thought because I was using “to:” when I should’ve been redirecting with “external:”, but regardless, it happens sometimes. I’ve been testing using FFox and Chrome, an apparently only in Chrome I experience this problem. Any ideas ?

Cheers,
M.

Can you provide a minimal project which shows that behaviour?

Try calling halt() after the redirect.

I’ll try to setup one to share. Thanks.

Done that already, but problem still happens some times, not always, but it does. Actually at first I thought it was because I was calling halt() after it, so I took it out, however ended up experiencing the same behavior.