Skip to content

http.request sends non-standard Host header when IP6 address + port is used #5308

Description

@himdel

When using the object form of http.request and using an IPv6 address as a hostname, and using a non-standard port, the Host header is created incorrectly...

Example code:

http.request({
  method: 'GET',
  hostname: '::1',
  port:'3000',
  path: '/api',
}, (res) => { console.log(res.statusCode, res.body); })
.end()

This triggers a HTTP request with:

GET /api HTTP/1.1
Host: ::1:3000

Compared to (for example) curl http://[::1]:3000/api, which does

GET /api HTTP/1.1
Host: [::1]:3000

For reference: https://tools.ietf.org/html/rfc7230#section-5.4

  • Kudos to @mpotra for helping me debug this issue..

Activity

  1. added
    httpIssues and PRs related to the http subsystem.
    on Feb 18, 2016
  2. mpotra commented on Feb 18, 2016

    @mpotra
    Contributor

    RFC that defines IPv6 hostnames in URIs: https://tools.ietf.org/html/rfc3986#section-3.2.2

  3. vkurchatkin commented on Feb 18, 2016

    @vkurchatkin
    Contributor

    What happens if you set hostname to [::1]?

  4. himdel commented on Feb 18, 2016

    @himdel
    Author

    @vkurchatkin it tries to resolve it as a hostname (triggers dns) and fails

  5. vkurchatkin commented on Feb 18, 2016

    @vkurchatkin
    Contributor

    Interesting. So rfc3986 says:

    A host identified by an Internet Protocol literal address, version 6
    [RFC3513] or later, is distinguished by enclosing the IP literal
    within square brackets ("[" and "]").

    So we just need a good enough way to detect if host is an ipv6 literal

  6. vkurchatkin commented on Feb 18, 2016

    @vkurchatkin
    Contributor

    I think checking for : is enough, since the only reason square brackets are used is to separate port's : from host's.

  7. jasnell commented on Apr 9, 2016

    @jasnell
    Member

    The fix landed for this.

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