Request: header field "host" includes port 80

Created on 13 Mar 2018  Â·  2Comments  Â·  Source: request/request

As the following code:
https://github.com/request/request/blob/bbb3a0bbbe173342de8462a2171765a39681b248/request.js#L294
If URI is "http://myhost:80/path", header field "host" will be set as "myhost:80".
Is it correct?

Note: before commit ff6d6c6e7a3b2c36618b5d1db662e10c929696e3, "host" header field will be set as "myhost"

Most helpful comment

Recently, most clients (including curl & wget) and browsers have started to drop the :80 & :443 port suffixes in the Host header, and include it only when it is neither of the two. Dropping the port prefix for known services is still RFC-compliant; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.23

Examples of other projects stripping the port suffix —

  1. Ruby - https://github.com/ruby/ruby/blob/d46336e71731aa64d71d4573b2741b7de43ec340/lib/net/http/generic_request.rb#L18
  2. AsyncHttpClient - https://github.com/AsyncHttpClient/async-http-client/issues/899
  3. waterlink/rack-reverse-proxy#3
  4. twilio/twilio-node#151
  5. https://github.com/bokeh/bokeh/pull/3513
  6. https://github.com/websocket-client/websocket-client/pull/248
  7. https://stackoverflow.com/a/19169664

Related request issue — https://github.com/request/request/issues/515

We discovered this was an issue while working with HAProxy, when backends use host-based routing. When the Host header includes the :80 or :443 suffix, the rules would not match and we'd get a 503 response.

@mikeal ~Can I send a PR for this?~ I've sent a PR here → https://github.com/request/request/pull/2904

All 2 comments

Recently, most clients (including curl & wget) and browsers have started to drop the :80 & :443 port suffixes in the Host header, and include it only when it is neither of the two. Dropping the port prefix for known services is still RFC-compliant; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.23

Examples of other projects stripping the port suffix —

  1. Ruby - https://github.com/ruby/ruby/blob/d46336e71731aa64d71d4573b2741b7de43ec340/lib/net/http/generic_request.rb#L18
  2. AsyncHttpClient - https://github.com/AsyncHttpClient/async-http-client/issues/899
  3. waterlink/rack-reverse-proxy#3
  4. twilio/twilio-node#151
  5. https://github.com/bokeh/bokeh/pull/3513
  6. https://github.com/websocket-client/websocket-client/pull/248
  7. https://stackoverflow.com/a/19169664

Related request issue — https://github.com/request/request/issues/515

We discovered this was an issue while working with HAProxy, when backends use host-based routing. When the Host header includes the :80 or :443 suffix, the rules would not match and we'd get a 503 response.

@mikeal ~Can I send a PR for this?~ I've sent a PR here → https://github.com/request/request/pull/2904

@zhaotian2470 This can be closed now, as v2.88.1 fixes this.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

IgorDePaula picture IgorDePaula  Â·  3Comments

Aranir picture Aranir  Â·  3Comments

lupo9557 picture lupo9557  Â·  3Comments

ghost picture ghost  Â·  3Comments

jasonxia23 picture jasonxia23  Â·  3Comments