Passing a URL instance with a CONNECT method results in an invalid path
Open
Nobody has claimed this yet.
http
- Dominant language
- JavaScript
- Stars
- 122k
- Forks
- 37.3k
- Avg merge
- 4d 2h
- Merged PRs (30d)
- 283
Description
- Version: >=v10.21.0
- Platform: Linux solus 5.6.18-156.current #1 SMP PREEMPT Sun Jun 21 07:16:38 UTC 2020 x86_64 GNU/Linux
- Subsystem: http, https, url
What steps will reproduce the bug?
const http = require('http');
const server = http.createServer();
server.on('connect', (request, stream) => {
console.log(request.url);
stream.end('HTTP/1.1 501 Not Implemented\r\n\r\n');
});
server.listen(error => {
if (error) {
throw error;
}
const url = new URL(`http://localhost:${server.address().port}/example.com`);
const request = http.request(url, {method: 'CONNECT'}).end();
request.once('connect', response => {
response.destroy();
server.close();
});
});
How often does it reproduce? Is there a required condition?
Always.
What is the expected behavior?
example.com
What do you see instead?
/example.com
Additional information
There is a workaround for this:
-const request = http.request(url, {method: 'CONNECT'}).end();
+const request = http.request({
+ hostname: url.hostname,
+ port: url.port,
+ path: 'example.com',
+ method: 'CONNECT'
+}).end();
/cc @yovanoc
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the provided Node.js reproduction using http.request, a URL instance, and the CONNECT method. Trace the HTTP client URL handling and inspect existing tests for CONNECT requests. Done means the server receives example.com rather than /example.com, with a regression test covering the behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 70/100