got-fetch icon indicating copy to clipboard operation
got-fetch copied to clipboard

Form submit redirect

Open Revadike opened this issue 2 years ago • 5 comments

So, I've noticed weird behavior and I think it's caused by how you handle redirects. When you make a POST request and the response has a redirect, you make a new request to the redirect URL, however this is again a POST request (with body), while instead it should be a simple GET request.

Revadike avatar Oct 15 '22 03:10 Revadike

I'm using the require version

Revadike avatar Oct 15 '22 03:10 Revadike

Hey, sorry for the late reply, this got lost in my github inbox.

Is is possible the status code is a 307? The spec for a 307 says the client should use the same method and body to make a request at the new location.

The 307 (Temporary Redirect) status code indicates that the target resource resides temporarily under a different URI and the user agent MUST NOT change the request method if it performs an automatic redirection to that URI.

https://httpwg.org/specs/rfc9110.html#status.307

alexghr avatar Oct 20 '22 08:10 alexghr

It's 302

Revadike avatar Oct 20 '22 13:10 Revadike

This wrapper doesn't automatically replay requests on redirection, that's all handled by got. For 302, the spec uses "may change to GET" instead of "should" or "must", I guess this was a choice made by got developers to keep the same method for 302s as well.

Note: For historical reasons, a user agent MAY change the request method from POST to GET for the subsequent request. If this behavior is undesired, the 307 (Temporary Redirect) status code can be used instead.

https://httpwg.org/specs/rfc9110.html#status.302

alexghr avatar Oct 21 '22 08:10 alexghr

In my case, the site breaks if you redirect using POST instead of GET.

Revadike avatar Oct 21 '22 13:10 Revadike