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
234a505e96
commit
0556f54544
@ -27,7 +27,7 @@ const {
|
|||||||
} = primordials;
|
} = primordials;
|
||||||
const { setImmediate } = require('timers');
|
const { setImmediate } = require('timers');
|
||||||
|
|
||||||
const { methods, HTTPParser } = internalBinding('http_parser');
|
const { methods, allMethods, HTTPParser } = internalBinding('http_parser');
|
||||||
const { getOptionValue } = require('internal/options');
|
const { getOptionValue } = require('internal/options');
|
||||||
const insecureHTTPParser = getOptionValue('--insecure-http-parser');
|
const insecureHTTPParser = getOptionValue('--insecure-http-parser');
|
||||||
|
|
||||||
@ -108,7 +108,7 @@ function parserOnHeadersComplete(versionMajor, versionMinor, headers, method,
|
|||||||
|
|
||||||
if (typeof method === 'number') {
|
if (typeof method === 'number') {
|
||||||
// server only
|
// server only
|
||||||
incoming.method = methods[method];
|
incoming.method = allMethods[method];
|
||||||
} else {
|
} else {
|
||||||
// client only
|
// client only
|
||||||
incoming.statusCode = statusCode;
|
incoming.statusCode = statusCode;
|
||||||
|
@ -1305,7 +1305,9 @@ void InitializeHttpParser(Local<Object> target,
|
|||||||
Integer::NewFromUnsigned(env->isolate(), kLenientAll));
|
Integer::NewFromUnsigned(env->isolate(), kLenientAll));
|
||||||
|
|
||||||
Local<Array> methods = Array::New(env->isolate());
|
Local<Array> methods = Array::New(env->isolate());
|
||||||
|
Local<Array> all_methods = Array::New(env->isolate());
|
||||||
size_t method_index = -1;
|
size_t method_index = -1;
|
||||||
|
size_t all_method_index = -1;
|
||||||
#define V(num, name, string) \
|
#define V(num, name, string) \
|
||||||
methods \
|
methods \
|
||||||
->Set(env->context(), \
|
->Set(env->context(), \
|
||||||
@ -1314,9 +1316,23 @@ void InitializeHttpParser(Local<Object> target,
|
|||||||
.Check();
|
.Check();
|
||||||
HTTP_METHOD_MAP(V)
|
HTTP_METHOD_MAP(V)
|
||||||
#undef 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(),
|
target->Set(env->context(),
|
||||||
FIXED_ONE_BYTE_STRING(env->isolate(), "methods"),
|
FIXED_ONE_BYTE_STRING(env->isolate(), "methods"),
|
||||||
methods).Check();
|
methods).Check();
|
||||||
|
target
|
||||||
|
->Set(env->context(),
|
||||||
|
FIXED_ONE_BYTE_STRING(env->isolate(), "allMethods"),
|
||||||
|
all_methods)
|
||||||
|
.Check();
|
||||||
|
|
||||||
t->Inherit(AsyncWrap::GetConstructorTemplate(env));
|
t->Inherit(AsyncWrap::GetConstructorTemplate(env));
|
||||||
SetProtoMethod(isolate, t, "close", Parser::Close);
|
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…
x
Reference in New Issue
Block a user