Skip to content

Commit 9aa5d49

Browse files
apapirovskiMylesBorins
authored andcommitted
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: #16337 Fixes: #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>
1 parent ce73ee5 commit 9aa5d49

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

lib/internal/http2/core.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2419,7 +2419,8 @@ function connect(authority, options, listener) {
24192419
debug(`connecting to ${authority}`);
24202420

24212421
const protocol = authority.protocol || options.protocol || 'https:';
2422-
const port = '' + (authority.port !== '' ? authority.port : 443);
2422+
const port = '' + (authority.port !== '' ?
2423+
authority.port : (authority.protocol === 'http:' ? 80 : 443));
24232424
const host = authority.hostname || authority.host || 'localhost';
24242425

24252426
let socket;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
if (!common.hasCrypto)
5+
common.skip('missing crypto');
6+
const assert = require('assert');
7+
const http2 = require('http2');
8+
const net = require('net');
9+
10+
// Verifies that port 80 gets set as expected
11+
12+
const connect = net.connect;
13+
net.connect = common.mustCall((...args) => {
14+
assert.strictEqual(args[0], '80');
15+
return connect(...args);
16+
});
17+
18+
const client = http2.connect('http://localhost:80');
19+
client.destroy();

0 commit comments

Comments
 (0)