Skip to content

Commit 6cca1be

Browse files
committed
Fix servername calculation
Fixes #77
1 parent fc9aebe commit 6cca1be

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

source/utils/calculate-server-name.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
'use strict';
2-
const net = require('net');
32
/* istanbul ignore file: https://github.com/nodejs/node/blob/v13.0.1/lib/_http_agent.js */
43

54
module.exports = options => {
@@ -15,9 +14,8 @@ module.exports = options => {
1514
}
1615
}
1716

18-
if (net.isIP(servername)) {
19-
return '';
20-
}
17+
// Removed empty string return for IP,
18+
// otherwise https://1.1.1.1/ would fail.
2119

2220
return servername;
2321
};

test/auto.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,19 @@ test.after('cleanup', async () => {
5454
await h2s.close();
5555
});
5656

57+
test('http2 via ip', async t => {
58+
const request = await http2.auto({
59+
protocol: 'https:',
60+
hostname: '127.0.0.1',
61+
port: h2s.address().port
62+
});
63+
request.end();
64+
65+
const response = await pEvent(request, 'response');
66+
const data = await getStream(response);
67+
t.is(data, 'h2');
68+
});
69+
5770
test('http2', async t => {
5871
const request = await http2.auto({
5972
protocol: 'https:',

0 commit comments

Comments
 (0)