Skip to content
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

Closed
wants to merge 5 commits into from
Closed

Conversation

XadillaX
Copy link
Contributor

@XadillaX XadillaX commented Mar 21, 2018

Fixes: #19457

Checklist
  • make -j4 test (UNIX) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added the http Issues or PRs related to the http subsystem. label Mar 21, 2018
setHost: 0,
port: this.address().port,
rejectUnauthorized: false
}, cb).on('error', thrower).end();
Copy link
Member

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().

@@ -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);
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about !!options.setHost?

Copy link
Member

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".

Copy link
Member

@lpinca lpinca Mar 21, 2018

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.

Copy link
Contributor Author

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?

Copy link
Member

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.

@lpinca
Copy link
Member

lpinca commented Mar 21, 2018

@lpinca lpinca added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Mar 21, 2018
@trivikr
Copy link
Member

trivikr commented Mar 22, 2018

We need to document options.setHost at https://nodejs.org/api/http.html#http_http_request_options_callback

@@ -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));
Copy link
Contributor Author

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.

@XadillaX
Copy link
Contributor Author

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
Copy link
Member

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));
Copy link
Member

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 varlet / const while you are at this line.

Copy link
Contributor Author

@XadillaX XadillaX Mar 26, 2018

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 vars in this file but not in this PR.

@trivikr
Copy link
Member

trivikr commented Mar 28, 2018

@XadillaX
Copy link
Contributor Author

@trivikr
Copy link
Member

trivikr commented Apr 3, 2018

Landed in b06f686

@trivikr trivikr closed this Apr 3, 2018
trivikr pushed a commit that referenced this pull request Apr 3, 2018
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]>
@Trott
Copy link
Member

Trott commented Apr 4, 2018

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...

Trott added a commit to Trott/io.js that referenced this pull request Apr 4, 2018
@Trott
Copy link
Member

Trott commented Apr 4, 2018

(#19784)

Trott added a commit to Trott/io.js that referenced this pull request Apr 4, 2018
Ref: nodejs#19502 (comment)

PR-URL: nodejs#19784
Reviewed-By: Teddy Katz <[email protected]>
Reviewed-By: Matheus Marchini <[email protected]>
@trivikr
Copy link
Member

trivikr commented Apr 4, 2018

Thanks @Trott for the quick fix

targos pushed a commit that referenced this pull request Apr 4, 2018
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]>
targos pushed a commit that referenced this pull request Apr 4, 2018
Ref: #19502 (comment)

PR-URL: #19784
Reviewed-By: Teddy Katz <[email protected]>
Reviewed-By: Matheus Marchini <[email protected]>
@targos targos mentioned this pull request Apr 4, 2018
@MylesBorins
Copy link
Contributor

Should this land on 6.x or 8.x?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. http Issues or PRs related to the http subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[http_client] setHost: true should not prevent a default "Host" header