Skip to content

Commit 150eb6c

Browse files
authored
Merge pull request #1805 from perrin4869/fix/ipv6-addresses
fix: ipv6 addresses parsing
2 parents 378f547 + 07954a1 commit 150eb6c

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

src/node/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ Request.prototype.request = function () {
754754
options.method = this.method;
755755
options.port = url.port;
756756
options.path = path;
757-
options.host = url.hostname;
757+
options.host = utils.normalizeHostname(url.hostname); // ex: [::1] -> ::1
758758
options.ca = this._ca;
759759
options.key = this._key;
760760
options.pfx = this._pfx;

src/utils.js

+5
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ exports.cleanHeader = (header, changesOrigin) => {
7272
return header;
7373
};
7474

75+
exports.normalizeHostname = (hostname) => {
76+
const [,normalized] = hostname.match(/^\[([^\]]+)\]$/) || [];
77+
return normalized || hostname;
78+
};
79+
7580
/**
7681
* Check if `obj` is an object.
7782
*

test/node/basic.js

+18
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,24 @@ describe('[node] request', () => {
134134
});
135135
});
136136

137+
if (doesntWorkInHttp2) {
138+
describe('ipv6 address', () => {
139+
it('should successfully query an ipv6 address', (done) => {
140+
request.get(`http://[::]:${process.env.ZUUL_PORT}/url?a=(b%29`).end((error, res) => {
141+
assert.equal('/url?a=(b%29', res.text);
142+
done();
143+
});
144+
});
145+
146+
it('should successfully query an ipv6 address', (done) => {
147+
request.get(`http://[::1]:${process.env.ZUUL_PORT}/url?a=(b%29`).end((error, res) => {
148+
assert.equal('/url?a=(b%29', res.text);
149+
done();
150+
});
151+
});
152+
});
153+
}
154+
137155
describe('.buffer()', () => {
138156
it('should enable buffering', (done) => {
139157
request

0 commit comments

Comments
 (0)