nginx/njs

Port missing in Host header when using ngx.fetch with non-standard port

Closed this issue · 3 comments

When using ngx.fetch() with a non-standard port, the Host header of the request contains only the hostname without the port.

The request that hits the server when using the code below contains the Host header with value myhost.com, when it should be myhost.com:8443.

ngx.fetch('https://myhost.com:8433/api')

As a workaround it's possible to manually set the Host header when making a fetch request:

ngx.fetch('https://myhost.com:8433/api', {headers: {'Host': 'myhost.com:8443'}})

Hi @mtyaka,

Thank you for the report. It will be fixed.

I wander, with what webservers you have issues? Because even though the port is missing in Host header, ngx.fetch() performs a connection to the specified port.

@mtyaka

Feel free to test the patch.

Thank you @xeioex!

I wander, with what webservers you have issues? Because even though the port is missing in Host header, ngx.fetch() performs a connection to the specified port.

I noticed this while connecting to a custom web service that logs the value of the Host header and I noticed inconsistencies between requests made from a browser and those made with ngx.fetch. It wasn't causing any real issues in my case, but it does deviate from the spec.