-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
http: fix request
when setHost
is true
#19502
Conversation
setHost: 0, | ||
port: this.address().port, | ||
rejectUnauthorized: false | ||
}, cb).on('error', thrower).end(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: .end()
is automatically called when using https.get()
.
lib/_http_client.js
Outdated
@@ -115,7 +115,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 || options.setHost); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just Boolean(options.setHost)
?
Also this is technically a breaking (semver) change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about !!options.setHost
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer Boolean
since it's more explicit (we are converting this to a boolean) rather than "we are negating this, which is coercing it to a boolean, and then negating it again to get the boolean value".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using only Boolean(options.setHost)
is not ok as undefined
should set setHost
to true
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't it a bugfix but breaking?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically yes but Imho it's semver-patch as I doubt anyone is relying on the current behavior. The option is currently not documented.
We need to document |
@@ -115,7 +115,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)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add the document.
I've updated the document. |
doc/api/http.md
Outdated
@@ -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}: When values `true`, force set request header `host` to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: "Specifies whether or not to automatically add the Host
header. Defaults to true
".
@@ -115,7 +115,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)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiny nit: It would be great if you could change var
→ let
/ const
while you are at this line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should open another PR to fix all var
s in this file but not in this PR.
Landed in b06f686 |
Fixes: #19457 PR-URL: #19502 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
Looks like this breaks CI because it violates the lint rule that landed after the last CI run. Will open a fast-track fix if no one else has done it yet... |
(#19784) |
Ref: nodejs#19502 (comment) PR-URL: nodejs#19784 Reviewed-By: Teddy Katz <[email protected]> Reviewed-By: Matheus Marchini <[email protected]>
Thanks @Trott for the quick fix |
Fixes: #19457 PR-URL: #19502 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
Ref: #19502 (comment) PR-URL: #19784 Reviewed-By: Teddy Katz <[email protected]> Reviewed-By: Matheus Marchini <[email protected]>
Should this land on 6.x or 8.x? |
Fixes: #19457
Checklist
make -j4 test
(UNIX) passes