Skip to content

Commit

Permalink
http: do not use llhttp indexes for array
Browse files Browse the repository at this point in the history
  • Loading branch information
ShogunPanda authored and marco-ippolito committed Feb 19, 2024
1 parent 85a030a commit 630de1c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/node_http_parser.cc
Expand Up @@ -1304,9 +1304,13 @@ void InitializeHttpParser(Local<Object> target,
Integer::NewFromUnsigned(env->isolate(), kLenientAll));

Local<Array> methods = Array::New(env->isolate());
#define V(num, name, string) \
methods->Set(env->context(), \
num, FIXED_ONE_BYTE_STRING(env->isolate(), #string)).Check();
size_t method_index = -1;
#define V(num, name, string) \
methods \
->Set(env->context(), \
++method_index, \
FIXED_ONE_BYTE_STRING(env->isolate(), #string)) \
.Check();
HTTP_METHOD_MAP(V)
#undef V
target->Set(env->context(),
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-http-methods.js
Expand Up @@ -52,6 +52,7 @@ const methods = [
'PROPPATCH',
'PURGE',
'PUT',
'QUERY',
'REBIND',
'REPORT',
'SEARCH',
Expand Down
10 changes: 7 additions & 3 deletions test/parallel/test-http-server-multiple-client-error.js
Expand Up @@ -28,14 +28,14 @@ const httpServer = http.createServer(common.mustNotCall());

httpServer.once('clientError', common.mustCall((err, socket) => {
assert.strictEqual(err.code, 'HPE_INVALID_METHOD');
assert.strictEqual(err.rawPacket.toString(), 'Q');
assert.strictEqual(err.rawPacket.toString(), '1');
socket.destroy();

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

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

socket.on('close', () => {
Expand Down

0 comments on commit 630de1c

Please sign in to comment.