mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 18:25:13 +08:00
Signed-off-by: Efe Karasakal <hi@efe.dev> PR-URL: https://github.com/nodejs/node/pull/64876 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Tim Perry <pimterry@gmail.com>
57 lines
1.3 KiB
JavaScript
57 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const http = require('http');
|
|
|
|
{
|
|
const server = http.createServer(common.mustNotCall());
|
|
|
|
server.on('connect', common.mustCall((req, socket) => {
|
|
assert.strictEqual(req.url, 'example.com');
|
|
socket.end('HTTP/1.1 501 Not Implemented\r\n\r\n');
|
|
}));
|
|
|
|
server.listen(0, common.mustCall(() => {
|
|
const port = server.address().port;
|
|
const req = http.request(
|
|
new URL(`http://localhost:${port}/example.com`),
|
|
{ method: 'CONNECT' },
|
|
);
|
|
|
|
req.on('connect', common.mustCall((res, socket) => {
|
|
assert.strictEqual(res.statusCode, 501);
|
|
socket.destroy();
|
|
server.close();
|
|
}));
|
|
|
|
req.end();
|
|
}));
|
|
}
|
|
|
|
{
|
|
const server = http.createServer(common.mustNotCall());
|
|
|
|
server.on('connect', common.mustCall((req, socket) => {
|
|
assert.strictEqual(req.url, '/example.com');
|
|
socket.end('HTTP/1.1 501 Not Implemented\r\n\r\n');
|
|
}));
|
|
|
|
server.listen(0, common.mustCall(() => {
|
|
const req = http.request({
|
|
host: 'localhost',
|
|
port: server.address().port,
|
|
method: 'CONNECT',
|
|
path: '/example.com',
|
|
});
|
|
|
|
req.on('connect', common.mustCall((res, socket) => {
|
|
assert.strictEqual(res.statusCode, 501);
|
|
socket.destroy();
|
|
server.close();
|
|
}));
|
|
|
|
req.end();
|
|
}));
|
|
}
|