mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
lib: use validateString
refactor validation code using validate function PR-URL: https://github.com/nodejs/node/pull/59296 Reviewed-By: Ethan Arrowood <ethan@arrowood.dev> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com>
This commit is contained in:
parent
5479930630
commit
824c0715bf
1 changed files with 4 additions and 4 deletions
|
@ -80,6 +80,7 @@ const {
|
||||||
const {
|
const {
|
||||||
validateInteger,
|
validateInteger,
|
||||||
validateBoolean,
|
validateBoolean,
|
||||||
|
validateString,
|
||||||
} = require('internal/validators');
|
} = require('internal/validators');
|
||||||
const { getTimerDuration } = require('internal/timers');
|
const { getTimerDuration } = require('internal/timers');
|
||||||
const {
|
const {
|
||||||
|
@ -270,12 +271,11 @@ function ClientRequest(input, options, cb) {
|
||||||
delete optsWithoutSignal.signal;
|
delete optsWithoutSignal.signal;
|
||||||
}
|
}
|
||||||
let method = options.method;
|
let method = options.method;
|
||||||
const methodIsString = (typeof method === 'string');
|
if (method != null) {
|
||||||
if (method !== null && method !== undefined && !methodIsString) {
|
validateString(method, 'options.method');
|
||||||
throw new ERR_INVALID_ARG_TYPE('options.method', 'string', method);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (methodIsString && method) {
|
if (method) {
|
||||||
if (!checkIsHttpToken(method)) {
|
if (!checkIsHttpToken(method)) {
|
||||||
throw new ERR_INVALID_HTTP_TOKEN('Method', method);
|
throw new ERR_INVALID_HTTP_TOKEN('Method', method);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue