Skip to content

http: add type checking for hostname - #12494

Closed
jasnell wants to merge 1 commit into
nodejs:masterfrom
jasnell:http-hostname-typechecking
Closed

http: add type checking for hostname#12494
jasnell wants to merge 1 commit into
nodejs:masterfrom
jasnell:http-hostname-typechecking

Conversation

@jasnell

Copy link
Copy Markdown
Member

Add type checking for options.hostname / options.host Maintains the use of undefined and null for default localhost, but other falsy values (like false, 0 and NaN) are rejected.

Refs: #12488

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

http

@jasnelljasnell added http Issues or PRs related to the http subsystem. semver-major PRs that contain breaking changes and should be released in the next major version. labels Apr 18, 2017
@nodejs-github-botnodejs-github-bot added the http Issues or PRs related to the http subsystem. label Apr 18, 2017
Comment threadlib/_http_client.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The first two conditionals can be shortened to just host != null or host != undefined.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Yeah... that's fine. I'm not a fan of != for that but shorter is better.

@mscdexmscdexApr 18, 2017

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It could be more efficient too, I have not checked how V8 compiles the two different methods of checking.

Comment threadlib/_http_client.js Outdated

@mscdexmscdexApr 18, 2017

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Perhaps we might use: "hostname"/"host" must either be a string, undefined, or null to keep with the theme of quoting property names?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Oh, right... good catch :-)

@jasnell

Copy link
Copy Markdown
MemberAuthor

@mscdex Updated

@cjihrigcjihrig left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM with a question.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why the common.noop here? I'd think we'd either want mustCall() or mustNotCall().

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

The main part that this is testing is that the call to http.request() does not throw synchronously. The fact that it will emit the error event is non-sequential to this particular test. This is set simply to avoid the unhandled error exception.

Comment threadlib/_http_client.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we include "host" as well, since this same function is used for both?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

I was stewing over that. Not sure. I'm fine with doing so just not sure if we should

Comment threadlib/_http_client.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If I'm not wrong this can be removed if host != null is used instead of host != undefined.

@jasnell
jasnellforce-pushed the http-hostname-typechecking branch from 97f9dc6 to 46c75f1CompareApril 19, 2017 22:38
@jasnell

Copy link
Copy Markdown
MemberAuthor

@mscdex@lpinca ... updated!

@jasnell

Copy link
Copy Markdown
MemberAuthor

@nodejs/ctc ... PTAL

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe include 0 as well, since it would have been treated as a false-y value?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This function is not doing any checks actually

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not common.mustNotCall() here?

@lpincalpincaApr 21, 2017

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@jasnell's reply on a comment above for same question

The main part that this is testing is that the call to http.request() does not throw synchronously. The fact that it will emit the error event is non-sequential to this particular test. This is set simply to avoid the unhandled error exception.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Mmmm, makes sense. Cool then.

@jasnell
jasnellforce-pushed the http-hostname-typechecking branch from 46c75f1 to 0b5dc3fCompareApril 21, 2017 17:15
Add type checking for options.hostname / options.host
Maintains the use of `undefined` and `null` for default `localhost`,
but other falsy values (like `false`, `0` and `NaN`) are rejected.
@jasnell
jasnellforce-pushed the http-hostname-typechecking branch from 0b5dc3f to 9ec4133CompareApril 21, 2017 17:32
@jasnell

Copy link
Copy Markdown
MemberAuthor

@jasnell

Copy link
Copy Markdown
MemberAuthor

Linting error was from an unrelated commit

jasnell added a commit that referenced this pull request Apr 24, 2017
Add type checking for options.hostname / options.host
Maintains the use of `undefined` and `null` for default `localhost`,
but other falsy values (like `false`, `0` and `NaN`) are rejected.
PR-URL: #12494
Ref: #12488
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
@jasnell

Copy link
Copy Markdown
MemberAuthor

Landed in 85a4e25

addaleax added a commit to addaleax/node that referenced this pull request Apr 25, 2017
This test would currently create HTTP requests to localhost:80
and would time out on machines that actually had an server listening
there.
To address that, `end()` the requests that are generated.
PR-URL: nodejs#12627
Ref: nodejs#12494
addaleax added a commit that referenced this pull request Apr 27, 2017
This test would currently create HTTP requests to localhost:80
and would time out on machines that actually had an server listening
there.
To address that, `end()` the requests that are generated.
PR-URL: #12627
Ref: #12494
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
@jasnelljasnell mentioned this pull request May 11, 2017
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

httpIssues or PRs related to the http subsystem.semver-majorPRs that contain breaking changes and should be released in the next major version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@jasnell@mscdex@ofrobots@thefourtheye@lpinca@cjihrig@nodejs-github-bot