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:
hotpineapple 2025-08-02 20:31:47 +09:00 committed by GitHub
parent 5479930630
commit 824c0715bf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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);
} }