diff --git a/lib/_http_client.js b/lib/_http_client.js index 9fd07e1676b8ff..6045c7aff8dc4c 100644 --- a/lib/_http_client.js +++ b/lib/_http_client.js @@ -186,9 +186,11 @@ function ClientRequest(input, options, cb) { const defaultPort = options.defaultPort || (this.agent && this.agent.defaultPort); - const port = options.port = options.port || defaultPort || 80; - const host = options.host = validateHost(options.hostname, 'hostname') || - validateHost(options.host, 'host') || 'localhost'; + const optsWithoutSignal = { __proto__: null, ...options }; + + const port = optsWithoutSignal.port = options.port || defaultPort || 80; + const host = optsWithoutSignal.host = validateHost(options.hostname, 'hostname') || + validateHost(options.host, 'host') || 'localhost'; const setHost = (options.setHost === undefined || Boolean(options.setHost)); @@ -200,6 +202,7 @@ function ClientRequest(input, options, cb) { const signal = options.signal; if (signal) { addAbortSignal(signal, this); + delete optsWithoutSignal.signal; } let method = options.method; const methodIsString = (typeof method === 'string'); @@ -326,12 +329,6 @@ function ClientRequest(input, options, cb) { this[kUniqueHeaders] = parseUniqueHeadersOption(options.uniqueHeaders); - let optsWithoutSignal = options; - if (optsWithoutSignal.signal) { - optsWithoutSignal = ObjectAssign({}, options); - delete optsWithoutSignal.signal; - } - // initiate connection if (this.agent) { this.agent.addRequest(this, optsWithoutSignal); diff --git a/test/parallel/test-http-client-input-function.js b/test/parallel/test-http-client-input-function.js index be65967cc65c82..eda5ef51785d0b 100644 --- a/test/parallel/test-http-client-input-function.js +++ b/test/parallel/test-http-client-input-function.js @@ -3,7 +3,6 @@ const common = require('../common'); const http = require('http'); const assert = require('assert'); -const ClientRequest = require('http').ClientRequest; { const server = http.createServer(common.mustCall((req, res) => { @@ -11,7 +10,7 @@ const ClientRequest = require('http').ClientRequest; res.end('hello world'); })).listen(80, '127.0.0.1'); - const req = new ClientRequest(common.mustCall((response) => { + const req = new http.ClientRequest(common.mustCall((response) => { let body = ''; response.setEncoding('utf8'); response.on('data', (chunk) => {