http2: allow port 80 in http2.connect
Due to how WHATWG-URL parser works, port numbers are omitted if they are the default port for a scheme. This meant that http2.connect could not accept connections on port 80 with http scheme. Fix this bug by detecting http: scheme and setting port to 80. PR-URL: https://github.com/nodejs/node/pull/16337 Fixes: https://github.com/nodejs/node/issues/14304 Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
This commit is contained in:
parent
eb2fbd159f
commit
c30f107103
@ -2419,7 +2419,8 @@ function connect(authority, options, listener) {
|
||||
debug(`connecting to ${authority}`);
|
||||
|
||||
const protocol = authority.protocol || options.protocol || 'https:';
|
||||
const port = '' + (authority.port !== '' ? authority.port : 443);
|
||||
const port = '' + (authority.port !== '' ?
|
||||
authority.port : (authority.protocol === 'http:' ? 80 : 443));
|
||||
const host = authority.hostname || authority.host || 'localhost';
|
||||
|
||||
let socket;
|
||||
|
19
test/parallel/test-http2-client-port-80.js
Normal file
19
test/parallel/test-http2-client-port-80.js
Normal file
@ -0,0 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
if (!common.hasCrypto)
|
||||
common.skip('missing crypto');
|
||||
const assert = require('assert');
|
||||
const http2 = require('http2');
|
||||
const net = require('net');
|
||||
|
||||
// Verifies that port 80 gets set as expected
|
||||
|
||||
const connect = net.connect;
|
||||
net.connect = common.mustCall((...args) => {
|
||||
assert.strictEqual(args[0], '80');
|
||||
return connect(...args);
|
||||
});
|
||||
|
||||
const client = http2.connect('http://localhost:80');
|
||||
client.destroy();
|
Loading…
x
Reference in New Issue
Block a user