1'use strict'; 2 3const common = require('../common'); 4const assert = require('assert'); 5 6const http = require('http'); 7const net = require('net'); 8 9{ 10 const msg = [ 11 'POST / HTTP/1.1', 12 'Host: 127.0.0.1', 13 'Transfer-Encoding: chunked', 14 'Transfer-Encoding: chunked-false', 15 'Connection: upgrade', 16 '', 17 '1', 18 'A', 19 '0', 20 '', 21 'GET /flag HTTP/1.1', 22 'Host: 127.0.0.1', 23 '', 24 '', 25 ].join('\r\n'); 26 27 const server = http.createServer(common.mustNotCall((req, res) => { 28 res.end(); 29 }, 1)); 30 31 server.listen(0, common.mustSucceed(() => { 32 const client = net.connect(server.address().port, 'localhost'); 33 34 let response = ''; 35 36 // Verify that the server listener is never called 37 38 client.on('data', common.mustCall((chunk) => { 39 response += chunk.toString('utf-8'); 40 })); 41 42 client.setEncoding('utf8'); 43 client.on('error', common.mustNotCall()); 44 client.on('end', common.mustCall(() => { 45 assert.strictEqual( 46 response, 47 'HTTP/1.1 400 Bad Request\r\nConnection: close\r\n\r\n' 48 ); 49 server.close(); 50 })); 51 client.write(msg); 52 client.resume(); 53 })); 54} 55 56{ 57 const msg = [ 58 'POST / HTTP/1.1', 59 'Host: 127.0.0.1', 60 'Transfer-Encoding: chunked', 61 ' , chunked-false', 62 'Connection: upgrade', 63 '', 64 '1', 65 'A', 66 '0', 67 '', 68 'GET /flag HTTP/1.1', 69 'Host: 127.0.0.1', 70 '', 71 '', 72 ].join('\r\n'); 73 74 const server = http.createServer(common.mustCall((request, response) => { 75 assert.notStrictEqual(request.url, '/admin'); 76 response.end('hello world'); 77 }), 1); 78 79 server.listen(0, common.mustSucceed(() => { 80 const client = net.connect(server.address().port, 'localhost'); 81 82 client.on('end', common.mustCall(function() { 83 server.close(); 84 })); 85 86 client.write(msg); 87 client.resume(); 88 })); 89} 90