Visitar URL original
http: do not use llhttp indexes for array · nodejs/node@5380cee · GitHub
Skip to content

Commit 5380cee

Browse files
committed
http: do not use llhttp indexes for array
1 parent eff5939 commit 5380cee

3 files changed

Lines changed: 15 additions & 6 deletions

File tree

‎src/node_http_parser.cc‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,9 +1288,13 @@ void InitializeHttpParser(Local<Object> target,
12881288
Integer::NewFromUnsigned(env->isolate(), kLenientAll));
12891289

12901290
Local<Array> methods = Array::New(env->isolate());
1291-
#define V(num, name, string) \
1292-
methods->Set(env->context(), \
1293-
num, FIXED_ONE_BYTE_STRING(env->isolate(), #string)).Check();
1291+
size_t method_index = -1;
1292+
#define V(num, name, string) \
1293+
methods \
1294+
->Set(env->context(), \
1295+
++method_index, \
1296+
FIXED_ONE_BYTE_STRING(env->isolate(), #string)) \
1297+
.Check();
12941298
HTTP_METHOD_MAP(V)
12951299
#undef V
12961300
target->Set(env->context(),

‎test/parallel/test-http-methods.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const methods = [
5252
'PROPPATCH',
5353
'PURGE',
5454
'PUT',
55+
'QUERY',
5556
'REBIND',
5657
'REPORT',
5758
'SEARCH',

‎test/parallel/test-http-server-multiple-client-error.js‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ const httpServer = http.createServer(common.mustNotCall());
2828

2929
httpServer.once('clientError', common.mustCall((err, socket) => {
3030
assert.strictEqual(err.code, 'HPE_INVALID_METHOD');
31-
assert.strictEqual(err.rawPacket.toString(), 'Q');
31+
assert.strictEqual(err.rawPacket.toString(), '1');
3232
socket.destroy();
3333

3434
httpServer.once('clientError', common.mustCall((err) => {
3535
assert.strictEqual(err.code, 'HPE_INVALID_METHOD');
3636
assert.strictEqual(
3737
err.rawPacket.toString(),
38-
'WE http://example.com HTTP/1.1\r\n\r\n'
38+
'23 http://example.com HTTP/1.1\r\n\r\n'
3939
);
4040
}));
4141
}));
@@ -44,7 +44,11 @@ netServer.listen(0, common.mustCall(() => {
4444
const socket = net.createConnection(netServer.address().port);
4545

4646
socket.on('connect', common.mustCall(() => {
47-
socket.end('QWE http://example.com HTTP/1.1\r\n\r\n');
47+
// Note: do not use letters here for the method.
48+
// There is a very small chance that a method with that initial
49+
// might be added in the future and thus this test might fail.
50+
// Numbers will likely never have this issue.
51+
socket.end('123 http://example.com HTTP/1.1\r\n\r\n');
4852
}));
4953

5054
socket.on('close', () => {

0 commit comments

Comments
 (0)