Skip to content

Commit cbe18d8

Browse files
quic: convert incoming :status header to number
Signed-off-by: Hallison Melo <hallss93@hotmail.com> Co-authored-by: Cursor <cursoragent@cursor.com> PR-URL: #63589 Fixes: #63557 Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Tim Perry <pimterry@gmail.com>
1 parent 114e356 commit cbe18d8

22 files changed

Lines changed: 114 additions & 44 deletions

doc/api/quic.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3990,8 +3990,9 @@ A few things to note:
39903990
the request is `HEADERS` followed by `END_STREAM`.
39913991
* The `onheaders` callback receives the response pseudo-headers and
39923992
regular headers in a single object with lowercase string keys.
3993-
After the callback returns, the same object is also accessible
3994-
via [`stream.headers`][].
3993+
For incoming headers, the `:status` pseudo-header is converted to
3994+
a `number`, matching HTTP/2 behavior. After the callback returns,
3995+
the same object is also accessible via [`stream.headers`][].
39953996
* Reading `for await (const chunks of stream)` consumes the response
39963997
body. Each iteration yields a `Uint8Array[]` batch of chunks.
39973998
* HTTP semantic helpers (URL parsing, method/status validation,

lib/internal/quic/quic.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,14 +1285,19 @@ function parseHeaderPairs(pairs) {
12851285
assert(pairs.length % 2 === 0);
12861286
const block = { __proto__: null };
12871287
for (let n = 0; n + 1 < pairs.length; n += 2) {
1288-
if (block[pairs[n]] !== undefined) {
1289-
if (ArrayIsArray(block[pairs[n]])) {
1290-
ArrayPrototypePush(block[pairs[n]], pairs[n + 1]);
1288+
const name = pairs[n];
1289+
let value = pairs[n + 1];
1290+
// Match HTTP/2 behavior: incoming :status is exposed as a number.
1291+
if (name === ':status')
1292+
value |= 0;
1293+
if (block[name] !== undefined) {
1294+
if (ArrayIsArray(block[name])) {
1295+
ArrayPrototypePush(block[name], value);
12911296
} else {
1292-
block[pairs[n]] = [block[pairs[n]], pairs[n + 1]];
1297+
block[name] = [block[name], value];
12931298
}
12941299
} else {
1295-
block[pairs[n]] = pairs[n + 1];
1300+
block[name] = value;
12961301
}
12971302
}
12981303
return block;

test/parallel/test-quic-h3-callback-errors.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ async function makeServer(onheadersHandler, extraOpts = {}) {
151151
':authority': 'localhost',
152152
},
153153
onheaders: mustCall(function(headers) {
154-
assert.strictEqual(headers[':status'], '200');
154+
assert.strictEqual(headers[':status'], 200);
155155
}),
156156
ontrailers: mustCall(function() {
157157
throw new Error('ontrailers sync error');
@@ -265,7 +265,7 @@ async function makeServer(onheadersHandler, extraOpts = {}) {
265265
':authority': 'localhost',
266266
},
267267
onheaders: mustCall(function(headers) {
268-
assert.strictEqual(headers[':status'], '200');
268+
assert.strictEqual(headers[':status'], 200);
269269
}),
270270
});
271271

test/parallel/test-quic-h3-close-behavior.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const decoder = new TextDecoder();
6262
':authority': 'localhost',
6363
},
6464
onheaders: mustCall((headers) => {
65-
assert.strictEqual(headers[':status'], '200');
65+
assert.strictEqual(headers[':status'], 200);
6666
}),
6767
});
6868

@@ -74,7 +74,7 @@ const decoder = new TextDecoder();
7474
':authority': 'localhost',
7575
},
7676
onheaders: mustCall((headers) => {
77-
assert.strictEqual(headers[':status'], '200');
77+
assert.strictEqual(headers[':status'], 200);
7878
}),
7979
});
8080

test/parallel/test-quic-h3-concurrent-requests.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const requests = paths.map(mustCall(async (path) => {
7272
':authority': 'localhost',
7373
},
7474
onheaders: mustCall((headers) => {
75-
assert.strictEqual(headers[':status'], '200');
75+
assert.strictEqual(headers[':status'], 200);
7676
headersReceived.resolve();
7777
}),
7878
});

test/parallel/test-quic-h3-datagram.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ const decoder = new TextDecoder();
8787
':authority': 'localhost',
8888
},
8989
onheaders: mustCall(function(headers) {
90-
assert.strictEqual(headers[':status'], '200');
90+
assert.strictEqual(headers[':status'], 200);
9191
}),
9292
});
9393

@@ -151,7 +151,7 @@ const decoder = new TextDecoder();
151151
':authority': 'localhost',
152152
},
153153
onheaders: mustCall((headers) => {
154-
assert.strictEqual(headers[':status'], '200');
154+
assert.strictEqual(headers[':status'], 200);
155155
}),
156156
});
157157

test/parallel/test-quic-h3-error-codes.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const decoder = new TextDecoder();
5555
':authority': 'localhost',
5656
},
5757
onheaders: mustCall(function(headers) {
58-
assert.strictEqual(headers[':status'], '200');
58+
assert.strictEqual(headers[':status'], 200);
5959
}),
6060
});
6161

@@ -106,7 +106,7 @@ const decoder = new TextDecoder();
106106
':authority': 'localhost',
107107
},
108108
onheaders: mustCall(function(headers) {
109-
assert.strictEqual(headers[':status'], '200');
109+
assert.strictEqual(headers[':status'], 200);
110110
}),
111111
});
112112

test/parallel/test-quic-h3-goaway.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ dc.subscribe('quic.session.goaway', mustCall((msg) => {
7878
await clientSession.opened;
7979

8080
const onClientHeaders = mustCall(function(headers) {
81-
assert.strictEqual(headers[':status'], '200');
81+
assert.strictEqual(headers[':status'], 200);
8282
if (++clientHeaderCount === 2) {
8383
bothHeadersReceived.resolve();
8484
}

test/parallel/test-quic-h3-header-validation.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ const decoder = new TextDecoder();
9191
},
9292
onheaders: mustCall(function(headers) {
9393
// Client should also receive lowercased response header names.
94-
assert.strictEqual(headers[':status'], '200');
94+
assert.strictEqual(headers[':status'], 200);
9595
assert.strictEqual(headers['content-type'], 'text/html');
9696
assert.strictEqual(headers['x-response-header'], 'ResponseValue');
9797

@@ -148,7 +148,7 @@ const decoder = new TextDecoder();
148148
':authority': 'localhost',
149149
},
150150
onheaders: mustCall((headers) => {
151-
assert.strictEqual(headers[':status'], '204');
151+
assert.strictEqual(headers[':status'], 204);
152152
}),
153153
});
154154

test/parallel/test-quic-h3-informational-headers.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ dc.subscribe('quic.stream.info', mustCall((msg) => {
3434
assert.ok(msg.stream, 'stream.info should include stream');
3535
assert.ok(msg.session, 'stream.info should include session');
3636
assert.ok(msg.headers, 'stream.info should include headers');
37-
assert.strictEqual(msg.headers[':status'], '103');
37+
assert.strictEqual(msg.headers[':status'], 103);
3838
}));
3939

4040
// quic.stream.headers also fires for the final response headers.
@@ -89,12 +89,12 @@ const stream = await clientSession.createBidirectionalStream({
8989
':authority': 'localhost',
9090
},
9191
oninfo: mustCall(function(headers) {
92-
assert.strictEqual(headers[':status'], '103');
92+
assert.strictEqual(headers[':status'], 103);
9393
assert.strictEqual(headers.link, '</style.css>; rel=preload; as=style');
9494
clientInfoReceived.resolve();
9595
}),
9696
onheaders: mustCall(function(headers) {
97-
assert.strictEqual(headers[':status'], '200');
97+
assert.strictEqual(headers[':status'], 200);
9898
assert.strictEqual(headers['content-type'], 'text/plain');
9999
clientHeadersReceived.resolve();
100100
}),
@@ -107,7 +107,7 @@ const body = await bytes(stream);
107107
assert.strictEqual(decoder.decode(body), responseBody);
108108

109109
// stream.headers should return the final (initial) headers, not 1xx.
110-
assert.strictEqual(stream.headers[':status'], '200');
110+
assert.strictEqual(stream.headers[':status'], 200);
111111

112112
await Promise.all([stream.closed, serverDone.promise]);
113113
await clientSession.close();

0 commit comments

Comments
 (0)