mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
http: correctly translate HTTP method
PR-URL: https://github.com/nodejs/node/pull/52701 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
8123be16a5
commit
65c8380a5a
@ -28,7 +28,7 @@ const {
|
||||
} = primordials;
|
||||
const { setImmediate } = require('timers');
|
||||
|
||||
const { methods, HTTPParser } = internalBinding('http_parser');
|
||||
const { methods, allMethods, HTTPParser } = internalBinding('http_parser');
|
||||
const { getOptionValue } = require('internal/options');
|
||||
const insecureHTTPParser = getOptionValue('--insecure-http-parser');
|
||||
|
||||
@ -109,7 +109,7 @@ function parserOnHeadersComplete(versionMajor, versionMinor, headers, method,
|
||||
|
||||
if (typeof method === 'number') {
|
||||
// server only
|
||||
incoming.method = methods[method];
|
||||
incoming.method = allMethods[method];
|
||||
} else {
|
||||
// client only
|
||||
incoming.statusCode = statusCode;
|
||||
|
@ -1304,7 +1304,9 @@ void InitializeHttpParser(Local<Object> target,
|
||||
Integer::NewFromUnsigned(env->isolate(), kLenientAll));
|
||||
|
||||
Local<Array> methods = Array::New(env->isolate());
|
||||
Local<Array> all_methods = Array::New(env->isolate());
|
||||
size_t method_index = -1;
|
||||
size_t all_method_index = -1;
|
||||
#define V(num, name, string) \
|
||||
methods \
|
||||
->Set(env->context(), \
|
||||
@ -1313,9 +1315,23 @@ void InitializeHttpParser(Local<Object> target,
|
||||
.Check();
|
||||
HTTP_METHOD_MAP(V)
|
||||
#undef V
|
||||
#define V(num, name, string) \
|
||||
all_methods \
|
||||
->Set(env->context(), \
|
||||
++all_method_index, \
|
||||
FIXED_ONE_BYTE_STRING(env->isolate(), #string)) \
|
||||
.Check();
|
||||
HTTP_ALL_METHOD_MAP(V)
|
||||
#undef V
|
||||
|
||||
target->Set(env->context(),
|
||||
FIXED_ONE_BYTE_STRING(env->isolate(), "methods"),
|
||||
methods).Check();
|
||||
target
|
||||
->Set(env->context(),
|
||||
FIXED_ONE_BYTE_STRING(env->isolate(), "allMethods"),
|
||||
all_methods)
|
||||
.Check();
|
||||
|
||||
t->Inherit(AsyncWrap::GetConstructorTemplate(env));
|
||||
SetProtoMethod(isolate, t, "close", Parser::Close);
|
||||
|
27
test/parallel/test-http-server-method.query.js
Normal file
27
test/parallel/test-http-server-method.query.js
Normal file
@ -0,0 +1,27 @@
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
const { strictEqual } = require('assert');
|
||||
const { createServer, request } = require('http');
|
||||
|
||||
const server = createServer(common.mustCall((req, res) => {
|
||||
strictEqual(req.method, 'QUERY');
|
||||
res.end('OK');
|
||||
}));
|
||||
|
||||
server.listen(0, common.mustCall(() => {
|
||||
const req = request({ port: server.address().port, method: 'QUERY' }, common.mustCall((res) => {
|
||||
strictEqual(res.statusCode, 200);
|
||||
|
||||
let buffer = '';
|
||||
res.setEncoding('utf-8');
|
||||
|
||||
res.on('data', (c) => buffer += c);
|
||||
res.on('end', common.mustCall(() => {
|
||||
strictEqual(buffer, 'OK');
|
||||
server.close();
|
||||
}));
|
||||
}));
|
||||
|
||||
req.end();
|
||||
}));
|
Loading…
Reference in New Issue
Block a user