http: add CONNECT method handling for default Host header with proxy · nodejs/node@eacfbd0 · GitHub
Skip to content

Commit eacfbd0

Browse files
Archkonrichardlau
authored andcommitted
http: add CONNECT method handling for default Host header with proxy
Signed-off-by: Archkon <180910180+Archkon@users.noreply.github.com> PR-URL: #64114 Fixes: #63945 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Tim Perry <pimterry@gmail.com>
1 parent f49704b commit eacfbd0

3 files changed

Lines changed: 41 additions & 2 deletions

File tree

lib/_http_client.js

Lines changed: 3 additions & 1 deletion
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const assert = require('assert');
5+
const http = require('http');
6+
const net = require('net');
7+
8+
const target = 'target.example.com:443';
9+
10+
const server = net.createServer(common.mustCall((socket) => {
11+
socket.once('data', common.mustCall((data) => {
12+
const rawRequest = data.toString();
13+
const requestLines = rawRequest.split('\r\n');
14+
15+
assert.strictEqual(requestLines[0], `CONNECT ${target} HTTP/1.1`);
16+
assert(requestLines.includes(`Host: ${target}`));
17+
18+
socket.end('HTTP/1.1 200 Connection established\r\n\r\n');
19+
}));
20+
}));
21+
22+
server.listen(0, common.localhostIPv4, common.mustCall(() => {
23+
const req = http.request({
24+
host: common.localhostIPv4,
25+
port: server.address().port,
26+
method: 'CONNECT',
27+
path: target,
28+
}, common.mustNotCall());
29+
30+
req.on('connect', common.mustCall((res, socket) => {
31+
assert.strictEqual(res.statusCode, 200);
32+
socket.destroy();
33+
server.close();
34+
}));
35+
36+
req.end();
37+
}));

test/parallel/test-tls-over-http-tunnel.js

Lines changed: 1 addition & 1 deletion

0 commit comments

Comments
 (0)