GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Passing a URL instance with a CONNECT method results in an invalid path · Issue #34347 · nodejs/node

Passing a URL instance with a CONNECT method results in an invalid path #34347

New issue
Copy link
New issue
Copy link
Closed
#64876
Closed
Passing a URL instance with a CONNECT method results in an invalid path#34347
#64876
Copy link
Labels
httpIssues and PRs related to the http subsystem.

Description

@szmarczak
szmarczak
opened on Jul 14, 2020
Issue body actions
  • Version: >=v10.21.0
  • Platform: Linux solus 5.6.18-156.current deps: update openssl to 1.0.1j #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

Activity

  1. bnoordhuis commented on Jul 14, 2020

    @bnoordhuis
    bnoordhuis
    on Jul 14, 2020
    Member
    More actions

    /example.com is the expected path. Why would you expect example.com?

  2. szmarczak commented on Jul 14, 2020

    @szmarczak
    szmarczak
    on Jul 14, 2020
    ContributorAuthor
    More actions

    https://tools.ietf.org/html/rfc7231#page-30

    A client sending a CONNECT request MUST send the authority form of
    request-target (Section 5.3 of [RFC7230]); i.e., the request-target
    consists of only the host name and port number of the tunnel
    destination, separated by a colon. For example,

     CONNECT server.example.com:80 HTTP/1.1
     Host: server.example.com:80
    
  3. bnoordhuis commented on Jul 14, 2020

    @bnoordhuis
    bnoordhuis
    on Jul 14, 2020
    Member
    More actions

    Right, so what you're asking is that http.request() special-cases (and validates?) CONNECT requests? The reason I said /example.com is expected is because the URL#pathname property is used as-is.

  4. bnoordhuis
    added
    httpIssues and PRs related to the http subsystem.
    on Jul 14, 2020
  5. szmarczak commented on Jul 14, 2020

    @szmarczak
    szmarczak
    on Jul 14, 2020
    ContributorAuthor
    More actions

    what you're asking is that http.request() special-cases (and validates?) CONNECT requests?

    The point is that it doesn't, but it should IMO :)

    The reason I said /example.com is expected is because the URL#pathname property is used as-is.

    Yup, I noticed that.

  6. bnoordhuis commented on Jul 14, 2020

    @bnoordhuis
    bnoordhuis
    on Jul 14, 2020
    Member
    More actions

    Shouldn't be a controversial change. Pull request welcome.

  7. preyunk commented on Jul 16, 2020

    @preyunk
    preyunk
    on Jul 16, 2020
    Contributor
    More actions

    @bnoordhuis
    I think we could exclude '/' from pathname at the time of conversion of url to options or should we change url.pathname to give out the value without '/'.

  8. szmarczak commented on Jul 16, 2020

    @szmarczak
    szmarczak
    on Jul 16, 2020
    ContributorAuthor
    More actions

    @preyunk That doesn't seem right. urlToOptions just converts the URL instance to an object, so it's expected to have leading slash in the pathname. It's just that it shouldn't be emitted when sending a CONNECT request.

  9. preyunk commented on Jul 16, 2020

    @preyunk
    preyunk
    on Jul 16, 2020
    Contributor
    More actions

    @szmarczak
    Ok I get it now.
    How about we check if options.path property has a leading slash (to prevent cases where it is set explicitly by providing path property in options) for 'CONNECT' method, then slice it to do the needful.

  10. szmarczak commented on Jul 16, 2020

    @szmarczak
    szmarczak
    on Jul 16, 2020
    ContributorAuthor
    More actions

    That's what's this issue is about...

  11. preyunk
    added 3 commits that reference this issue on Jul 17, 2020

    http: fixed invalid path with connect method

    4f71f9f
  12. preyunk
    added 2 commits that reference this issue on Aug 5, 2020

    http: fixed invalid path with connect method

    edd8f6e

    http: fixed invalid path with connect method

    0825564
  13. github-actions commented on Jun 27, 2026

    @github-actions
    github-actionsBot
    on Jun 27, 2026 – with GitHub Actions
    Contributor
    More actions

    This issue has been marked as stale due to 210 days of inactivity.
    It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.

  14. github-actions
    added
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Jun 27, 2026
  15. drake90001 commented on Jul 24, 2026

    @drake90001
    drake90001
    on Jul 24, 2026
    More actions

    Fox this please because shits still broken

  16. github-actions
    removed
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Jul 25, 2026
  17. nodejs-github-bot
    closed this as completedin #64876on Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    httpIssues and PRs related to the http subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.