From 630de1cdfdc88efa552eeba70262b6e9828a7729 Mon Sep 17 00:00:00 2001 From: Paolo Insogna Date: Tue, 13 Feb 2024 11:14:40 +0100 Subject: [PATCH] http: do not use llhttp indexes for array --- src/node_http_parser.cc | 10 +++++++--- test/parallel/test-http-methods.js | 1 + .../parallel/test-http-server-multiple-client-error.js | 10 +++++++--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/node_http_parser.cc b/src/node_http_parser.cc index e2475f3b4990d2..d6732a7ddc571f 100644 --- a/src/node_http_parser.cc +++ b/src/node_http_parser.cc @@ -1304,9 +1304,13 @@ void InitializeHttpParser(Local target, Integer::NewFromUnsigned(env->isolate(), kLenientAll)); Local 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(), diff --git a/test/parallel/test-http-methods.js b/test/parallel/test-http-methods.js index 1142c175ecdb20..7b9243999835ee 100644 --- a/test/parallel/test-http-methods.js +++ b/test/parallel/test-http-methods.js @@ -52,6 +52,7 @@ const methods = [ 'PROPPATCH', 'PURGE', 'PUT', + 'QUERY', 'REBIND', 'REPORT', 'SEARCH', diff --git a/test/parallel/test-http-server-multiple-client-error.js b/test/parallel/test-http-server-multiple-client-error.js index 4ac41d295e3d3e..9323132f4af4a5 100644 --- a/test/parallel/test-http-server-multiple-client-error.js +++ b/test/parallel/test-http-server-multiple-client-error.js @@ -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' ); })); })); @@ -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', () => {