Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(https2): ipv6 addresses url #1829

Merged
merged 1 commit into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dist.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"no-undef": "off",
"no-unused-vars": "off",
"no-useless-escape": "off",
"no-obj-calls": "off",
"no-cond-assign": "off",
"no-redeclare": "off",
"node/no-exports-assign": "off",
Expand Down
9 changes: 7 additions & 2 deletions src/node/http2wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
};
}

function normalizeIpv6Host(host) {
return net.isIP(host) === 6 ? `[${host}]` : host;
}

class Request extends Stream {
constructor(protocol, options) {
super();
Expand Down Expand Up @@ -48,11 +52,12 @@

this._headers = {};

const normalizedHost = normalizeIpv6Host(host);
const session = http2.connect(
`${protocol}//${host}:${port}`,
`${protocol}//${normalizedHost}:${port}`,
sessionOptions
);
this.setHeader('host', `${host}:${port}`);
this.setHeader('host', `${normalizedHost}:${port}`);

session.on('error', (error) => this.emit('error', error));

Expand All @@ -73,7 +78,7 @@
}
}

setNoDelay(bool) {

Check warning on line 81 in src/node/http2wrapper.js

View workflow job for this annotation

GitHub Actions / test (14.x)

'bool' is defined but never used

Check warning on line 81 in src/node/http2wrapper.js

View workflow job for this annotation

GitHub Actions / test (16.x)

'bool' is defined but never used

Check warning on line 81 in src/node/http2wrapper.js

View workflow job for this annotation

GitHub Actions / test (18.x)

'bool' is defined but never used
// We can not use setNoDelay with HTTP/2.
// Node 10 limits http2session.socket methods to ones safe to use with HTTP/2.
// See also https://nodejs.org/api/http2.html#http2_http2session_socket
Expand All @@ -95,7 +100,7 @@

const frame = this.session.request(headers);

frame.once('response', (headers, flags) => {

Check warning on line 103 in src/node/http2wrapper.js

View workflow job for this annotation

GitHub Actions / test (14.x)

'flags' is defined but never used

Check warning on line 103 in src/node/http2wrapper.js

View workflow job for this annotation

GitHub Actions / test (16.x)

'flags' is defined but never used

Check warning on line 103 in src/node/http2wrapper.js

View workflow job for this annotation

GitHub Actions / test (18.x)

'flags' is defined but never used
headers = this.mapToHttpHeader(headers);
frame.headers = headers;
frame.statusCode = headers[HTTP2_HEADER_STATUS];
Expand Down Expand Up @@ -179,7 +184,7 @@
frame.end(data);
}

abort(data) {

Check warning on line 187 in src/node/http2wrapper.js

View workflow job for this annotation

GitHub Actions / test (14.x)

'data' is defined but never used

Check warning on line 187 in src/node/http2wrapper.js

View workflow job for this annotation

GitHub Actions / test (16.x)

'data' is defined but never used

Check warning on line 187 in src/node/http2wrapper.js

View workflow job for this annotation

GitHub Actions / test (18.x)

'data' is defined but never used
const frame = this.getFrame();
frame.close(NGHTTP2_CANCEL);
this.session.destroy();
Expand Down
24 changes: 11 additions & 13 deletions test/node/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,23 +134,21 @@ describe('[node] request', () => {
});
});

if (doesntWorkInHttp2) {
describe('ipv6 address', () => {
it('should successfully query an ipv6 address', (done) => {
request.get(`http://[::]:${process.env.ZUUL_PORT}/url?a=(b%29`).end((error, res) => {
assert.equal('/url?a=(b%29', res.text);
done();
});
describe('ipv6 address', () => {
it('should successfully query an ipv6 address', (done) => {
request.get(`http://[::]:${process.env.ZUUL_PORT}/url?a=(b%29`).end((error, res) => {
assert.equal('/url?a=(b%29', res.text);
done();
});
});

it('should successfully query an ipv6 address', (done) => {
request.get(`http://[::1]:${process.env.ZUUL_PORT}/url?a=(b%29`).end((error, res) => {
assert.equal('/url?a=(b%29', res.text);
done();
});
it('should successfully query an ipv6 address', (done) => {
request.get(`http://[::1]:${process.env.ZUUL_PORT}/url?a=(b%29`).end((error, res) => {
assert.equal('/url?a=(b%29', res.text);
done();
});
});
}
});

describe('.buffer()', () => {
it('should enable buffering', (done) => {
Expand Down
Loading