Skip to content

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

Closed
@himdel

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..

Metadata

Metadata

Assignees

No one assigned

    Labels

    httpIssues or 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