Skip to content

Undocumented behavior for handling options of http.request #47624

Closed
@ZEDCWT

Description

@ZEDCWT

Version

v20.0.0

Platform

Microsoft Windows NT 10.0.19045.0 x64

Subsystem

No response

What steps will reproduce the bug?

var Opt = require('url').parse('https://httpbin.org/get');
require('https')
	.request({...Opt,path : Opt.path + '?A=B'},S => S.on('data',D => console.log(D.toString('UTF8'))))
	.end()

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior? Why is that the expected behavior?

Running using v19.9.0, it prints

{
  "args": {
    "A": "B"
  },
  "headers": {
    "Host": "httpbin.org",
    ....
  },
  ....
  "url": "https://httpbin.org/get?A=B"
}

What do you see instead?

{
  "args": {},
  "headers": {
    "Host": "httpbin.org",
    ...
  },
  ...
  "url": "https://httpbin.org/get"
}

Additional information

Before #47339, url.isURL checks if property href & origin exists, and it changed to check if property href & protocol exist now.
So before that, the Opt above goes to the else branch of ClientRequest, but now it goes to the else if (isURL(input)) branch, in which it ignores the path property given and just glues pathname & search together.
Reading the document, it says url can be a string or a URL object also never mentions anything about search or pathname.
since I'm not providing a WHATWG URL object, I'm expecting to call this signature http.request(options[, callback]) retaining my path property as what v19 and before do.

Metadata

Metadata

Assignees

Labels

httpIssues or PRs related to the http subsystem.urlIssues and PRs related to the legacy built-in url module.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions