Skip to content

Commit

Permalink
Fix Agent.normalizeAuthority(...)
Browse files Browse the repository at this point in the history
  • Loading branch information
szmarczak committed Feb 28, 2020
1 parent 06fe862 commit 8c38c7e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
6 changes: 5 additions & 1 deletion source/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,11 @@ class Agent extends EventEmitter {
url = new URL(url);
}

return servername ? `https://${servername}:${url.port || 443}` : url.origin;
if (servername && url.hostname !== servername) {
url.hostname = servername;
}

return url.origin;
}

normalizeOptions(options) {
Expand Down
2 changes: 1 addition & 1 deletion source/client-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ class ClientRequest extends Writable {
// Forwards data
stream.on('data', chunk => {
if (!response.push(chunk)) {
this.pause();
stream.pause();
}
});

Expand Down
9 changes: 9 additions & 0 deletions test/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -1006,3 +1006,12 @@ test('errors on failure', async t => {
t.is(error.port, 443);
t.is(error.address, '127.0.0.1');
});

test('properly normalizes origin', t => {
t.is(Agent.normalizeOrigin('https://google.com'), 'https://google.com');
t.is(Agent.normalizeOrigin('https://google.com', 'gmail.com'), 'https://gmail.com');
t.is(Agent.normalizeOrigin('https://google.com:443'), 'https://google.com');
t.is(Agent.normalizeOrigin('https://google.com:443', 'gmail.com'), 'https://gmail.com');
t.is(Agent.normalizeOrigin('https://google.com:4434'), 'https://google.com:4434');
t.is(Agent.normalizeOrigin('https://google.com:4434', 'gmail.com'), 'https://gmail.com:4434');
});
10 changes: 10 additions & 0 deletions test/auto.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,3 +471,13 @@ test.serial('does not reuse HTTP/1.1 TLS sockets if custom `createConnection` op

t.pass();
});

test('http2 works (Internet connection)', async t => {
const request = await http2.auto('https://httpbin.org/anything');
request.end();

const response = await pEvent(request, 'response');
response.resume();

t.is(response.headers[':status'], 200);
});

0 comments on commit 8c38c7e

Please sign in to comment.