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

FIX: port derivation with 'hostname' instead of 'host' given #88

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

freitag-solutions
Copy link

Problem:

When using 'hostname' instead of 'host' (as recommended by https://nodejs.org/api/http.html#http_http_request_options_callback) and omitting the 'port' option the request's port will get set to 'window.location.port' (independently of protocol and anything). This is not the case when using 'host' instead of 'hostname'.

Example (actual status):

window.location.port = 8080;
http.get({hostname: 'external-host', protocol: 'https'}); 
    // resolves to: 'https://external-host:8080/'

Example (target status):

window.location.port = 8080;
http.get({hostname: 'external-host', protocol: 'https'}); 
    // resolves to: 'https://external-host:443/'

Solution:

Derive 'host' from 'hostname' before the port is resolved.

Possible impact:

The original behavior MAY be correct for requests which target the same host and protocol as the current application. E.g. when running an application from 'http://localhost:8080' requests to {hostname: 'localhost', protocol: 'http:', port: null} COULD be resolved just as requests to {protocol: 'http', port: null} to target 'http://localhost:8080' (this pull requests resolves the former request to 'http://localhost:80').

Since I wasn't able to find any documentation about the intended behavior this is open to discussion. In my personal opinion omitting the 'port' option should always result in using default ports. Only in the special case when omitting both, hostname and port, the application may assume the request targets the host and port the current application was served from.

Unfortunately this behavior cannot be derived from node-http since the problem only occurs in browsers.

@freitag-solutions freitag-solutions changed the title Reorder host resolution to cascade into port detection FIX: port derivation with 'hostname' instead of 'host' given Jun 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants