Skip to content

http.get method() ignores query params when passing an URL as first argument #22162

Closed
@gabriel-araujjo

Description

@gabriel-araujjo
  • Version: v8.10.0
  • Platform: Linux 4.15.0-29-generic Ubuntu SMP Tue Jul 17 15:39:52 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
  • Subsystem: http

When passing an URL with query params as the first argument to http.get() method, the query is ignored.

const URL = require('url');
const http = require('http');
const assert = require('assert');

function parseJsonResp(next) {
   return function(resp) {
     var raw = '';
     resp.on('data', function(chunk) {
       raw += chunk;
     });
     resp.on('end', function() {
       next(null, JSON.parse(raw));
     });
  }
};

const url = URL.parse('http://httpbin.org/get');
url.query = {foo: 'bar'}

http.get(url, parseJsonResp(function(err, obj) {
  assert(obj.args.foo === 'bar'); // It fails here
}));

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to the documentations.httpIssues or PRs related to the http subsystem.questionIssues that look for answers.urlIssues and PRs related to the legacy built-in url module.whatwg-urlIssues and PRs related to the WHATWG URL implementation.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions