Skip to content

Commit

Permalink
fix: Strip brackets from IPv6 literals when parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
serverwentdown committed Sep 2, 2021
1 parent 2603c67 commit 7d20fea
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,13 @@ export const getNodeRequestOptions = request => {
if (!headers.has('Connection') && !agent) {
headers.set('Connection', 'close');
}

// Because of the differences in paring between Node.js's standard library and WHATWG's spec, IPv6 literal hostnames ([::1]) are treated as domain names by Node.js's standard library.
// Strip off the square brackets in WHATWG's URL.hostname before handing it to Node.js.
let hostname = parsedURL.hostname;
if (hostname.startsWith('[') && hostname.endsWith(']')) {
hostname = hostname.substring(1, hostname.length - 1)
}

// HTTP-network fetch step 4.2
// chunked encoding is handled by Node.js
Expand All @@ -210,7 +217,7 @@ export const getNodeRequestOptions = request => {
const requestOptions = {
path: parsedURL.pathname + search,
pathname: parsedURL.pathname,
hostname: parsedURL.hostname,
hostname: hostname,
protocol: parsedURL.protocol,
port: parsedURL.port,
hash: parsedURL.hash,
Expand Down

0 comments on commit 7d20fea

Please sign in to comment.