diff options
author | 2023-09-29 00:03:58 -0700 | |
---|---|---|
committer | 2023-09-29 00:03:58 -0700 | |
commit | 6514dcf4cbc63cff89f3cac59598872caf776f0b (patch) | |
tree | f0e2d20f076e7785d4009290dd38d47af790c9e4 /src | |
parent | d3caf37b49c8158c50e3bed71b9f8b2838437a9e (diff) | |
download | bun-6514dcf4cbc63cff89f3cac59598872caf776f0b.tar.gz bun-6514dcf4cbc63cff89f3cac59598872caf776f0b.tar.zst bun-6514dcf4cbc63cff89f3cac59598872caf776f0b.zip |
Fixes #6053 (#6162)
Fixes #6053
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/http_client_async.zig | 48 |
1 files changed, 45 insertions, 3 deletions
diff --git a/src/http_client_async.zig b/src/http_client_async.zig index a8ba8d367..15e29f345 100644 --- a/src/http_client_async.zig +++ b/src/http_client_async.zig @@ -3541,8 +3541,50 @@ pub fn handleResponseMetadata( { // - Set request’s method to `GET` and request’s body to null. this.method = .GET; - // - For each headerName of request-body-header name, delete headerName from request’s header list. - this.header_entries.len = 0; + + // https://github.com/oven-sh/bun/issues/6053 + if (this.header_entries.len > 0) { + // A request-body-header name is a header name that is a byte-case-insensitive match for one of: + // - `Content-Encoding` + // - `Content-Language` + // - `Content-Location` + // - `Content-Type` + const @"request-body-header" = &.{ + "Content-Encoding", + "Content-Language", + "Content-Location", + }; + var i: usize = 0; + + // - For each headerName of request-body-header name, delete headerName from request’s header list. + const names = this.header_entries.items(.name); + var len = names.len; + outer: while (i < len) { + const name = this.headerStr(names[i]); + switch (name.len) { + "Content-Type".len => { + const hash = hashHeaderName(name); + if (hash == comptime hashHeaderConst("Content-Type")) { + _ = this.header_entries.orderedRemove(i); + len = this.header_entries.len; + continue :outer; + } + }, + "Content-Encoding".len => { + const hash = hashHeaderName(name); + inline for (@"request-body-header") |hash_value| { + if (hash == comptime hashHeaderConst(hash_value)) { + _ = this.header_entries.orderedRemove(i); + len = this.header_entries.len; + continue :outer; + } + } + }, + else => {}, + } + i += 1; + } + } } // https://fetch.spec.whatwg.org/#concept-http-redirect-fetch @@ -3557,7 +3599,7 @@ pub fn handleResponseMetadata( if (name.len == "Authorization".len) { const hash = hashHeaderName(name); if (hash == authorization_header_hash) { - this.header_entries.swapRemove(i); + this.header_entries.orderedRemove(i); break; } } |