mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
http: fix request
when setHost
is true
Fixes: https://github.com/nodejs/node/issues/19457 PR-URL: https://github.com/nodejs/node/pull/19502 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yuta Hiroto <hello@hiroppy.me> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
This commit is contained in:
parent
2ec6995555
commit
b06f686f88
@ -1858,6 +1858,8 @@ changes:
|
||||
details. Any [`Duplex`][] stream is a valid return value.
|
||||
* `timeout` {number}: A number specifying the socket timeout in milliseconds.
|
||||
This will set the timeout before the socket is connected.
|
||||
* `setHost` {boolean}: Specifies whether or not to automatically add the
|
||||
`Host` header. Defaults to `true`.
|
||||
* `callback` {Function}
|
||||
* Returns: {http.ClientRequest}
|
||||
|
||||
|
@ -116,7 +116,7 @@ function ClientRequest(options, cb) {
|
||||
var host = options.host = validateHost(options.hostname, 'hostname') ||
|
||||
validateHost(options.host, 'host') || 'localhost';
|
||||
|
||||
var setHost = (options.setHost === undefined);
|
||||
var setHost = (options.setHost === undefined || Boolean(options.setHost));
|
||||
|
||||
this.socketPath = options.socketPath;
|
||||
this.timeout = options.timeout;
|
||||
|
@ -16,7 +16,7 @@ const httpsServer = https.createServer(options, reqHandler);
|
||||
|
||||
function reqHandler(req, res) {
|
||||
console.log(`Got request: ${req.headers.host} ${req.url}`);
|
||||
if (req.url === '/setHostFalse5') {
|
||||
if (req.url.startsWith('/setHostFalse')) {
|
||||
assert.strictEqual(req.headers.host, undefined);
|
||||
} else {
|
||||
assert.strictEqual(
|
||||
@ -97,6 +97,34 @@ function testHttps() {
|
||||
setHost: false,
|
||||
port: this.address().port,
|
||||
rejectUnauthorized: false
|
||||
}, cb).on('error', thrower);
|
||||
|
||||
https.request({
|
||||
method: 'GET',
|
||||
path: `/${counter++}`,
|
||||
host: 'localhost',
|
||||
setHost: true,
|
||||
//agent: false,
|
||||
port: this.address().port,
|
||||
rejectUnauthorized: false
|
||||
}, cb).on('error', thrower).end();
|
||||
|
||||
https.get({
|
||||
method: 'GET',
|
||||
path: `/setHostFalse${counter++}`,
|
||||
host: 'localhost',
|
||||
setHost: 0,
|
||||
port: this.address().port,
|
||||
rejectUnauthorized: false
|
||||
}, cb).on('error', thrower);
|
||||
|
||||
https.get({
|
||||
method: 'GET',
|
||||
path: `/setHostFalse${counter++}`,
|
||||
host: 'localhost',
|
||||
setHost: null,
|
||||
port: this.address().port,
|
||||
rejectUnauthorized: false
|
||||
}, cb).on('error', thrower);
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user