aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2023-09-29 00:03:58 -0700
committerGravatar GitHub <noreply@github.com> 2023-09-29 00:03:58 -0700
commit6514dcf4cbc63cff89f3cac59598872caf776f0b (patch)
treef0e2d20f076e7785d4009290dd38d47af790c9e4
parentd3caf37b49c8158c50e3bed71b9f8b2838437a9e (diff)
downloadbun-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>
-rw-r--r--src/http_client_async.zig48
-rw-r--r--test/js/web/fetch/fetch.test.ts4
2 files changed, 48 insertions, 4 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;
}
}
diff --git a/test/js/web/fetch/fetch.test.ts b/test/js/web/fetch/fetch.test.ts
index 100f6e79e..85e2296cd 100644
--- a/test/js/web/fetch/fetch.test.ts
+++ b/test/js/web/fetch/fetch.test.ts
@@ -1501,10 +1501,12 @@ describe("should strip headers", () => {
method: "POST",
headers: {
"I-Am-Here": "yes",
+ "Content-Language": "This should be stripped",
},
});
- expect(headers.get("I-Am-Here")).toBeNull();
+ expect(headers.get("I-Am-Here")).toBe("yes");
+ expect(headers.get("Content-Language")).toBeNull();
expect(url).toEndWith("/redirected");
expect(redirected).toBe(true);
server.stop(true);