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

Closed
wants to merge 1 commit into from

Conversation

nfriedly
Copy link
Contributor

The issue:
http.request() treats host as an alternate form of hostname, which it sort of is, except that host is (normally) allowed to contain a port number.

Before this change, if host contains a port number and there isn't a hostname 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 fallback hostname and the second (if present) as a fallback port. ("Fallback" meaning that the values from the host field are only used when the hostname and port 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.

The issue:
http.request() treats host as an alternate form of hostname, which
it sort of is, except that host is (normally) allowed to contain a
port number.

Before this change, if host contains a port number and there isn't
a hostname 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 fallback hostname and the second (if present) as a
fallback port. ("Fallback" meaning that the values from the host
field are only used when the hostname and port fields aren't set.)
@Fishrock123
Copy link
Contributor

io.js is better for now, yeah. :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants