mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 10:15:07 +08:00
Signed-off-by: Archkon <180910180+Archkon@users.noreply.github.com> PR-URL: https://github.com/nodejs/node/pull/64114 Fixes: https://github.com/nodejs/node/issues/63945 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Tim Perry <pimterry@gmail.com>
38 lines
988 B
JavaScript
38 lines
988 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const http = require('http');
|
|
const net = require('net');
|
|
|
|
const target = 'target.example.com:443';
|
|
|
|
const server = net.createServer(common.mustCall((socket) => {
|
|
socket.once('data', common.mustCall((data) => {
|
|
const rawRequest = data.toString();
|
|
const requestLines = rawRequest.split('\r\n');
|
|
|
|
assert.strictEqual(requestLines[0], `CONNECT ${target} HTTP/1.1`);
|
|
assert(requestLines.includes(`Host: ${target}`));
|
|
|
|
socket.end('HTTP/1.1 200 Connection established\r\n\r\n');
|
|
}));
|
|
}));
|
|
|
|
server.listen(0, common.localhostIPv4, common.mustCall(() => {
|
|
const req = http.request({
|
|
host: common.localhostIPv4,
|
|
port: server.address().port,
|
|
method: 'CONNECT',
|
|
path: target,
|
|
}, common.mustNotCall());
|
|
|
|
req.on('connect', common.mustCall((res, socket) => {
|
|
assert.strictEqual(res.statusCode, 200);
|
|
socket.destroy();
|
|
server.close();
|
|
}));
|
|
|
|
req.end();
|
|
}));
|