mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
lib: refactor to reuse validators
PR-URL: https://github.com/nodejs/node/pull/38608 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Zijian Liu <lxxyxzj@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
committed by
James M Snell
parent
2eeb4e1d94
commit
5d7b6c2497
@@ -51,12 +51,15 @@ const { AsyncResource } = require('async_hooks');
|
||||
const { async_id_symbol } = require('internal/async_hooks').symbols;
|
||||
const {
|
||||
codes: {
|
||||
ERR_INVALID_ARG_TYPE,
|
||||
ERR_OUT_OF_RANGE,
|
||||
},
|
||||
} = require('internal/errors');
|
||||
const { once } = require('internal/util');
|
||||
const { validateNumber, validateOneOf } = require('internal/validators');
|
||||
const {
|
||||
validateNumber,
|
||||
validateOneOf,
|
||||
validateString,
|
||||
} = require('internal/validators');
|
||||
|
||||
const kOnKeylog = Symbol('onkeylog');
|
||||
const kRequestOptions = Symbol('requestOptions');
|
||||
@@ -344,10 +347,7 @@ function calculateServerName(options, req) {
|
||||
let servername = options.host;
|
||||
const hostHeader = req.getHeader('host');
|
||||
if (hostHeader) {
|
||||
if (typeof hostHeader !== 'string') {
|
||||
throw new ERR_INVALID_ARG_TYPE('options.headers.host',
|
||||
'String', hostHeader);
|
||||
}
|
||||
validateString(hostHeader, 'options.headers.host');
|
||||
|
||||
// abc => abc
|
||||
// abc:123 => abc
|
||||
|
||||
Reference in New Issue
Block a user