From 75460306dbe0766e70c661e30380e63e6878424d Mon Sep 17 00:00:00 2001 From: Don McCurdy Date: Tue, 20 Mar 2018 15:24:42 -0700 Subject: [PATCH 1/2] Include brackets for IPv6 host header. --- lib/XMLHttpRequest.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/XMLHttpRequest.js b/lib/XMLHttpRequest.js index d02da6c..02a531e 100644 --- a/lib/XMLHttpRequest.js +++ b/lib/XMLHttpRequest.js @@ -111,7 +111,7 @@ exports.XMLHttpRequest = function() { this.responseXML = ""; this.status = null; this.statusText = null; - + // Whether cross-site Access-Control requests should be made using // credentials such as cookies or authorization headers this.withCredentials = false; @@ -344,6 +344,9 @@ exports.XMLHttpRequest = function() { // Set the Host header or the server may reject the request headers.Host = host; if (!((ssl && port === 443) || port === 80)) { + if (url.host[0] === '[') { + headers.Host = '[' + headers.Host + ']'; + } headers.Host += ":" + url.port; } From 60def8de0240f889ae8f8e37133099bc99f70545 Mon Sep 17 00:00:00 2001 From: Don McCurdy Date: Wed, 21 Mar 2018 09:33:54 -0700 Subject: [PATCH 2/2] Escape IPv6 address regardless of whether port is specified. --- lib/XMLHttpRequest.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/XMLHttpRequest.js b/lib/XMLHttpRequest.js index 02a531e..bada957 100644 --- a/lib/XMLHttpRequest.js +++ b/lib/XMLHttpRequest.js @@ -343,10 +343,11 @@ exports.XMLHttpRequest = function() { // Set the Host header or the server may reject the request headers.Host = host; + // IPv6 addresses must be escaped with brackets + if (url.host[0] === "[") { + headers.Host = "[" + headers.Host + "]"; + } if (!((ssl && port === 443) || port === 80)) { - if (url.host[0] === '[') { - headers.Host = '[' + headers.Host + ']'; - } headers.Host += ":" + url.port; }