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 {
validateInteger,
validateBoolean,
validateString,
} = require('internal/validators');
const { getTimerDuration } = require('internal/timers');
const {
@ -270,12 +271,11 @@ function ClientRequest(input, options, cb) {
delete optsWithoutSignal.signal;
}
let method = options.method;
const methodIsString = (typeof method === 'string');
if (method !== null && method !== undefined && !methodIsString) {
throw new ERR_INVALID_ARG_TYPE('options.method', 'string', method);
if (method != null) {
validateString(method, 'options.method');
}
if (methodIsString && method) {
if (method) {
if (!checkIsHttpToken(method)) {
throw new ERR_INVALID_HTTP_TOKEN('Method', method);
}