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

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

@CrabBot

Description

@CrabBot

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions