Differences between a redirect 302 and a 307?

1

What is the difference between a redirect 302 and a redirect 307 ?

The W3 specification seems to indicate that both are used for temporary redirects.

    
asked by Lucas D.A.W. 23.05.2018 в 17:34
source

1 answer

1

In version 1.0 of HTTP, there was only the 302 with the meaning of "the request you just made, you must do it again in this other URL". Implicitly it was understood that you should use the same HTTP verb. Therefore, if you made a GET uri and received a 302 , then you should do again GET with the new URI. In this sense it would be equivalent to the modern 307.

But nevertheless, and contradicting the expected use, it became fashionable to use 302 in response to a form submission. Thus, if a page contained an HTML form, and the user after filling it pressed the "Send" button, typically the browser made a request POST to the URI specified in the form. The server could simply process the form data and return a 200 Ok , along with a results page, but this caused an undesired effect, and if the user "reloaded" the results page, the POST would be done again , resubmitting the form and with the risk of a non-idempotent operation.

To avoid this it became customary to respond to that POST with a 302 , so that the browser would then do GET to that new URL that would show the results page. So, a reload of that page would do a new GET instead of repeating the POST .

Thus, the code 302 had become ambiguous. Either it had its originally intended meaning that the resource had been temporarily moved and the verb about the new URL had to be repeated, or the new meaning adopted "de facto" that the 302 response to a POST should involve the use of a GET to get the results page.

To undo that ambiguity, HTTP version 1.1 introduced two new status codes:

  • 303 : This would be the meaning "do a GET to this URI" after having done a POST before.
  • 307 : This would be the original meaning of 302 : "repeat the same verb about this other URI".

By the way, in HTTP / 1.1 should not be used 302, which has been replaced by 303/307 as I just explained. But there are still sites that continue to use it in response to a POST.

    
answered by 23.05.2018 / 17:55
source