diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index 633ef219441b79..1d0bcde56961fe 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -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; diff --git a/test/parallel/test-http2-client-port-80.js b/test/parallel/test-http2-client-port-80.js new file mode 100644 index 00000000000000..a9d19eb5b9f008 --- /dev/null +++ b/test/parallel/test-http2-client-port-80.js @@ -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();