Skip to content

Commit

Permalink
tls: handle ipv6 addresses in host-header
Browse files Browse the repository at this point in the history
When an http-client requests a url with the hostname
specified as an IPv6 address, the Host: header will
have the following format:

Host: [::1]:3000

The servername in this case should be '::1'.

Fixes: nodejs#14736
  • Loading branch information
mattiasholmlund committed Sep 23, 2017
1 parent 7a95392 commit 4097d43
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/_http_agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,12 @@ Agent.prototype.addRequest = function addRequest(req, options, port/*legacy*/,
options.servername = options.host;
const hostHeader = req.getHeader('host');
if (hostHeader) {
options.servername = hostHeader.replace(/:.*$/, '');
// abc => abc
// abc:123 => abc
// [::1] => ::1
// [::1]:123 => ::1
options.servername = hostHeader.replace(/:[^\]]+$/, '')
.replace(/^\[(.*)\]$/, '$1');
}
}

Expand Down

0 comments on commit 4097d43

Please sign in to comment.