got-fetch
got-fetch copied to clipboard
Form submit redirect
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.
I'm using the require version
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
It's 302
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
In my case, the site breaks if you redirect using POST instead of GET.