From c77e4f16a840095aa1f3d27a9e5a0e9ef3ead359 Mon Sep 17 00:00:00 2001 From: Rishi Panthee Date: Tue, 6 Jun 2023 21:22:50 -0500 Subject: [PATCH 1/2] fix(http): remove brackets from hostname --- lib/adapters/http.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/adapters/http.js b/lib/adapters/http.js index bf6c2fffcb..a117dbccce 100755 --- a/lib/adapters/http.js +++ b/lib/adapters/http.js @@ -399,7 +399,7 @@ export default isHttpAdapterSupported && function httpAdapter(config) { if (config.socketPath) { options.socketPath = config.socketPath; } else { - options.hostname = parsed.hostname; + options.hostname = parsed.hostname.startsWith("[") ? parsed.hostname.slice(1, -1) : parsed.hostname; options.port = parsed.port; setProxy(options, config.proxy, protocol + '//' + parsed.hostname + (parsed.port ? ':' + parsed.port : '') + options.path); } From ce87fb17b09102a06a9c292b1a23972f394eef92 Mon Sep 17 00:00:00 2001 From: Rishi Panthee Date: Sat, 21 Oct 2023 21:59:29 -0500 Subject: [PATCH 2/2] test(http): add tests for ipv6 literal strings --- test/unit/adapters/http.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/test/unit/adapters/http.js b/test/unit/adapters/http.js index 6e07c7739b..315ac4bbe4 100644 --- a/test/unit/adapters/http.js +++ b/test/unit/adapters/http.js @@ -146,6 +146,44 @@ describe('supports http with nodejs', function () { delete process.env.no_proxy; }); + it('should support IPv4 literal strings', function (done) { + + var data = { + firstName: 'Fred', + lastName: 'Flintstone', + emailAddr: 'fred@example.com' + }; + + server = http.createServer(function (req, res) { + res.setHeader('Content-Type', 'application/json'); + res.end(JSON.stringify(data)); + }).listen(4444, function () { + axios.get('http://127.0.0.1:4444/').then(function (res) { + assert.deepEqual(res.data, data); + done(); + }).catch(done); + }); + }); + + it('should support IPv6 literal strings', function (done) { + + var data = { + firstName: 'Fred', + lastName: 'Flintstone', + emailAddr: 'fred@example.com' + }; + + server = http.createServer(function (req, res) { + res.setHeader('Content-Type', 'application/json'); + res.end(JSON.stringify(data)); + }).listen(4444, function () { + axios.get('http://[::1]:4444/').then(function (res) { + assert.deepEqual(res.data, data); + done(); + }).catch(done); + }); + }); + it('should throw an error if the timeout property is not parsable as a number', function (done) { server = http.createServer(function (req, res) {