Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/http/H2Client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@
}
#[inline]
pub(crate) fn h2_build_request(&mut self, body_len: usize) -> picohttp::Request<'static> {
// SAFETY: `build_request` returns a `Request<'_>` whose borrowed
// slices point only at (a) the thread-local
// `SHARED_REQUEST_HEADERS_BUF` static and (b) `self.header_buf`,
// which is itself `&'static [u8]` — neither is tied to the `&mut
// self` borrow. Erasing to `'static` lets
// `ClientSession::attach` re-borrow `client` while the
// slices point only at (a) the per-HTTP-thread request-header
// scratch (`SHARED_REQUEST_HEADERS_BUF` or its `_OVERFLOW` Vec)
// and (b) `self.header_buf`, which is itself `&'static [u8]` —
// neither is tied to the `&mut self` borrow. Erasing to `'static`
// lets `ClientSession::attach` re-borrow `client` while the
Comment thread
robobun marked this conversation as resolved.
// `Request` is still live. Same pattern as lib.rs `on_writable`.

Check failure on line 135 in src/http/H2Client.rs

View check run for this annotation

Claude / Claude Code Review

Second commit reverted the entire lib.rs fix — bug is not fixed

Commit cd1bc69c accidentally reverted the entire `src/http/lib.rs` change from 195b14c4 — the cumulative PR diff to `lib.rs` is now empty, so `MAX_USER_HEADERS` and the `will_append` silent-drop guard are still in place at HEAD and the bug is not fixed. The two new `it.each([251, 300])` tests will fail with `Received: 250`, and this SAFETY comment now references an `_OVERFLOW` Vec that doesn't exist. Restore the `lib.rs` hunk from 195b14c4.
Comment thread
robobun marked this conversation as resolved.
unsafe { self.build_request(body_len).detach_lifetime() }
}
}
Expand Down
37 changes: 37 additions & 0 deletions test/js/web/fetch/fetch_headers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,43 @@ describe("Headers", async () => {
}
});

it.each([251, 300])("sends every request header field on the wire (%i user headers)", async N => {
// build_request() previously capped user headers at 250 (256-slot scratch
// minus 6 defaults) and silently dropped the rest; the origin must receive
// every field.
const { promise: gotHead, resolve, reject } = Promise.withResolvers();
const srv = net.createServer(s => {
let b = Buffer.alloc(0);
s.on("data", d => {
b = Buffer.concat([b, d]);
if (b.indexOf("\r\n\r\n") >= 0) {
resolve(b.toString("latin1").split("\r\n\r\n")[0]);
s.end("HTTP/1.1 200 OK\r\nContent-Length: 2\r\nConnection: close\r\n\r\nok");
}
});
s.once("error", reject);
});
srv.listen(0, "127.0.0.1");
await once(srv, "listening");
try {
const port = srv.address().port;
const headers = {};
for (let i = 0; i < N; i++) headers["x-" + String(i).padStart(4, "0")] = "v";
const [res, head] = await Promise.all([fetch(`http://127.0.0.1:${port}/`, { headers }), gotHead]);
await res.text();
const lines = head.split("\r\n").slice(1);
const received = lines.filter(l => l.startsWith("x-")).sort();
const expected = Object.keys(headers)
.map(k => `${k}: v`)
.sort();
expect(received.length).toBe(N);
expect(received).toEqual(expected);
expect(res.status).toBe(200);
} finally {
await new Promise(r => srv.close(r));
}
});

it("Invalid values for well-known headers name the header, not its index", () => {
// The HTTPHeaderName fast path must report the header's name (e.g. 'Location'),
// not its numeric enum value (e.g. '51').
Expand Down
Loading