Skip to content

Commit 630de1c

Browse files
ShogunPandamarco-ippolito
authored andcommitted
http: do not use llhttp indexes for array
1 parent 85a030a commit 630de1c

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

src/node_http_parser.cc

+7-3
Original file line numberDiff line numberDiff line change
@@ -1304,9 +1304,13 @@ void InitializeHttpParser(Local<Object> target,
13041304
Integer::NewFromUnsigned(env->isolate(), kLenientAll));
13051305

13061306
Local<Array> methods = Array::New(env->isolate());
1307-
#define V(num, name, string) \
1308-
methods->Set(env->context(), \
1309-
num, FIXED_ONE_BYTE_STRING(env->isolate(), #string)).Check();
1307+
size_t method_index = -1;
1308+
#define V(num, name, string) \
1309+
methods \
1310+
->Set(env->context(), \
1311+
++method_index, \
1312+
FIXED_ONE_BYTE_STRING(env->isolate(), #string)) \
1313+
.Check();
13101314
HTTP_METHOD_MAP(V)
13111315
#undef V
13121316
target->Set(env->context(),

test/parallel/test-http-methods.js

+1
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

+7-3
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)