This repository was archived by the owner on Oct 7, 2020. It is now read-only.
Make http.request correctly parse {host: "hostname:port"} #72
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The issue:
http.request()
treatshost
as an alternate form ofhostname
, which it sort of is, except thathost
is (normally) allowed to contain a port number.Before this change, if
host
contains a port number and there isn't ahostname
field to override it,http.request()
attempts a DNS lookup on the entire host field, including the port number. This always fails.The fix:
If a host field is present, split it around
':'
and use the first portion as a fallbackhostname
and the second (if present) as a fallbackport
. ("Fallback" meaning that the values from thehost
field are only used when thehostname
andport
fields aren't set.)Includes a test to verify the correct behavior.
I originally filed an issue on joyent/node and submitted a patch there, but @jasnell said that this might be a better fit for nodejs/io.js or nodejs/node, so I'm sending the same patch to each. (The io.js patch is at nodejs/node#2271) Please merge into whichever repo is appropriate and close the other one.