Skip to content

Commit

Permalink
http2: allow port 80 in http2.connect
Browse files Browse the repository at this point in the history
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.

Fixes: nodejs#14304
  • Loading branch information
apapirovski committed Oct 23, 2017
1 parent ba4a0a6 commit e756215
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -2413,7 +2413,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;
Expand Down
19 changes: 19 additions & 0 deletions test/parallel/test-http2-client-port-80.js
Original file line number Diff line number Diff line change
@@ -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();

0 comments on commit e756215

Please sign in to comment.