|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const common = require('../common'); |
| 4 | +const assert = require('assert'); |
| 5 | +const http = require('http'); |
| 6 | + |
| 7 | +{ |
| 8 | + const server = http.createServer(common.mustNotCall()); |
| 9 | + |
| 10 | + server.on('connect', common.mustCall((req, socket) => { |
| 11 | + assert.strictEqual(req.url, 'example.com'); |
| 12 | + socket.end('HTTP/1.1 501 Not Implemented\r\n\r\n'); |
| 13 | + })); |
| 14 | + |
| 15 | + server.listen(0, common.mustCall(() => { |
| 16 | + const port = server.address().port; |
| 17 | + const req = http.request( |
| 18 | + new URL(`http://localhost:${port}/example.com`), |
| 19 | + { method: 'CONNECT' }, |
| 20 | + ); |
| 21 | + |
| 22 | + req.on('connect', common.mustCall((res, socket) => { |
| 23 | + assert.strictEqual(res.statusCode, 501); |
| 24 | + socket.destroy(); |
| 25 | + server.close(); |
| 26 | + })); |
| 27 | + |
| 28 | + req.end(); |
| 29 | + })); |
| 30 | +} |
| 31 | + |
| 32 | +{ |
| 33 | + const server = http.createServer(common.mustNotCall()); |
| 34 | + |
| 35 | + server.on('connect', common.mustCall((req, socket) => { |
| 36 | + assert.strictEqual(req.url, '/example.com'); |
| 37 | + socket.end('HTTP/1.1 501 Not Implemented\r\n\r\n'); |
| 38 | + })); |
| 39 | + |
| 40 | + server.listen(0, common.mustCall(() => { |
| 41 | + const req = http.request({ |
| 42 | + host: 'localhost', |
| 43 | + port: server.address().port, |
| 44 | + method: 'CONNECT', |
| 45 | + path: '/example.com', |
| 46 | + }); |
| 47 | + |
| 48 | + req.on('connect', common.mustCall((res, socket) => { |
| 49 | + assert.strictEqual(res.statusCode, 501); |
| 50 | + socket.destroy(); |
| 51 | + server.close(); |
| 52 | + })); |
| 53 | + |
| 54 | + req.end(); |
| 55 | + })); |
| 56 | +} |
0 commit comments