aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-12-01 21:15:34 -0800
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-12-01 21:15:34 -0800
commit9f4d7690ace86048abad38cfaf51eb99e944449b (patch)
treed39cc4cd0450d7a96a7d0ad3a97e623f73ce7121 /src
parent5854d395259f4084b1d66e9f12b54085f277527e (diff)
downloadbun-9f4d7690ace86048abad38cfaf51eb99e944449b.tar.gz
bun-9f4d7690ace86048abad38cfaf51eb99e944449b.tar.zst
bun-9f4d7690ace86048abad38cfaf51eb99e944449b.zip
[fetch] Treat 302 like 303
Diffstat (limited to 'src')
-rw-r--r--src/http_client_async.zig19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/http_client_async.zig b/src/http_client_async.zig
index 11150ef50..b946c3aa6 100644
--- a/src/http_client_async.zig
+++ b/src/http_client_async.zig
@@ -1967,7 +1967,7 @@ pub fn handleResponseMetadata(
const is_redirect = this.state.pending_response.status_code >= 300 and this.state.pending_response.status_code <= 399;
- if (location.len > 0 and this.remaining_redirect_count > 0 and this.follow_redirects) {
+ if (is_redirect and this.follow_redirects and location.len > 0 and this.remaining_redirect_count > 0) {
switch (this.state.pending_response.status_code) {
302, 301, 307, 308, 303 => {
if (strings.indexOf(location, "://")) |i| {
@@ -2049,8 +2049,23 @@ pub fn handleResponseMetadata(
this.redirect = url_buf;
}
+ // 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.
+ if (response.status_code == 302) {
+ switch (this.method) {
+ .GET, .HEAD => {},
+ else => {
+ this.method = .GET;
+ },
+ }
+ }
+
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/303
- if (response.status_code == 303) {
+ if (response.status_code == 303 and this.method != .HEAD) {
this.method = .GET;
}