Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Inconsistent url object handling in http.request and url.format #3770

Closed
CrabBot opened this issue Jul 25, 2012 · 2 comments
Closed

Inconsistent url object handling in http.request and url.format #3770

CrabBot opened this issue Jul 25, 2012 · 2 comments

Comments

@CrabBot
Copy link

CrabBot commented Jul 25, 2012

Related to #1390.

If you url.parse a url, alter the pathname, and then pass it to http.request, path takes precedence. However, if you first url.format the url, pathname takes precedence:

var uri = url.parse('http://www.google.com/search?q=asdf');
uri.pathname += '/naaaaah';

var r1 = http.get(uri, function(res) {
    if (r2.path && r1.path !== r2.path) throw new Error('Mismatch');
});

var r2 = http.get(url.parse(url.format(uri)), function(res) {
    if (r1.path && r1.path !== r2.path) throw new Error('Mismatch');
});

Obviously, this is because http.request does not consider pathname. However, this is inconsistent then with the url.parse's partial compliance regarding hostname:

hostname: To support url.parse() hostname is preferred over host

and the options string:

options can be an object or a string. If options is a string, it is automatically parsed with url.parse().

See documentation.

@chrisdickinson
Copy link

Hey @tjfontaine, can I get a quick thumbs up or down on whether we're okay with (slightly) breaking backwards compat in order to unify behaviors a bit?

@jasnell
Copy link
Member

jasnell commented May 18, 2015

Closing the issue here in favor of the ongoing work on the url module in io.js (nodejs/node#1650)

@jasnell jasnell closed this as completed May 18, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants