| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -186,9 +186,11 @@ function ClientRequest(input, options, cb) { | |||
| 186 | 186 | const defaultPort = options.defaultPort || | |
| 187 | 187 | (this.agent && this.agent.defaultPort); | |
| 188 | 188 | ||
| 189 | - const port = options.port = options.port || defaultPort || 80; | ||
| 190 | - const host = options.host = validateHost(options.hostname, 'hostname') || | ||
| 191 | - validateHost(options.host, 'host') || 'localhost'; | ||
| 189 | + const optsWithoutSignal = { __proto__: null, ...options }; | ||
| 190 | + | ||
| 191 | + const port = optsWithoutSignal.port = options.port || defaultPort || 80; | ||
| 192 | + const host = optsWithoutSignal.host = validateHost(options.hostname, 'hostname') || | ||
| 193 | + validateHost(options.host, 'host') || 'localhost'; | ||
| 192 | 194 | ||
| 193 | 195 | const setHost = (options.setHost === undefined || Boolean(options.setHost)); | |
| 194 | 196 | ||
@@ -200,6 +202,7 @@ function ClientRequest(input, options, cb) { | |||
| 200 | 202 | const signal = options.signal; | |
| 201 | 203 | if (signal) { | |
| 202 | 204 | addAbortSignal(signal, this); | |
| 205 | + delete optsWithoutSignal.signal; | ||
| 203 | 206 | } | |
| 204 | 207 | let method = options.method; | |
| 205 | 208 | const methodIsString = (typeof method === 'string'); | |
@@ -326,12 +329,6 @@ function ClientRequest(input, options, cb) { | |||
| 326 | 329 | ||
| 327 | 330 | this[kUniqueHeaders] = parseUniqueHeadersOption(options.uniqueHeaders); | |
| 328 | 331 | ||
| 329 | - let optsWithoutSignal = options; | ||
| 330 | - if (optsWithoutSignal.signal) { | ||
| 331 | - optsWithoutSignal = ObjectAssign({}, options); | ||
| 332 | - delete optsWithoutSignal.signal; | ||
| 333 | - } | ||
| 334 | - | ||
| 335 | 332 | // initiate connection | |
| 336 | 333 | if (this.agent) { | |
| 337 | 334 | this.agent.addRequest(this, optsWithoutSignal); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,29 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common'); | ||
| 4 | + const http = require('http'); | ||
| 5 | + const assert = require('assert'); | ||
| 6 | + | ||
| 7 | + { | ||
| 8 | + const server = http.createServer(common.mustCall((req, res) => { | ||
| 9 | + res.writeHead(200); | ||
| 10 | + res.end('hello world'); | ||
| 11 | + })).listen(0, '127.0.0.1'); | ||
| 12 | + | ||
| 13 | + server.on('listening', common.mustCall(() => { | ||
| 14 | + const req = new http.ClientRequest(server.address(), common.mustCall((response) => { | ||
| 15 | + let body = ''; | ||
| 16 | + response.setEncoding('utf8'); | ||
| 17 | + response.on('data', (chunk) => { | ||
| 18 | + body += chunk; | ||
| 19 | + }); | ||
| 20 | + | ||
| 21 | + response.on('end', common.mustCall(() => { | ||
| 22 | + assert.strictEqual(body, 'hello world'); | ||
| 23 | + server.close(); | ||
| 24 | + })); | ||
| 25 | + })); | ||
| 26 | + | ||
| 27 | + req.end(); | ||
| 28 | + })); | ||
| 29 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,14 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + require('../common'); | ||
| 4 | + const assert = require('assert'); | ||
| 5 | + const ClientRequest = require('http').ClientRequest; | ||
| 6 | + | ||
| 7 | + { | ||
| 8 | + assert.throws(() => { | ||
| 9 | + new ClientRequest({ insecureHTTPParser: 'wrongValue' }); | ||
| 10 | + }, { | ||
| 11 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 12 | + message: /insecureHTTPParser/ | ||
| 13 | + }, 'http request should throw when passing invalid insecureHTTPParser'); | ||
| 14 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments