11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciconst assert = require('assert'); 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciconst http = require('http'); 71cb0ef41Sopenharmony_ciconst net = require('net'); 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ci{ 101cb0ef41Sopenharmony_ci const msg = [ 111cb0ef41Sopenharmony_ci 'POST / HTTP/1.1', 121cb0ef41Sopenharmony_ci 'Host: 127.0.0.1', 131cb0ef41Sopenharmony_ci 'Transfer-Encoding: chunked', 141cb0ef41Sopenharmony_ci 'Transfer-Encoding: chunked-false', 151cb0ef41Sopenharmony_ci 'Connection: upgrade', 161cb0ef41Sopenharmony_ci '', 171cb0ef41Sopenharmony_ci '1', 181cb0ef41Sopenharmony_ci 'A', 191cb0ef41Sopenharmony_ci '0', 201cb0ef41Sopenharmony_ci '', 211cb0ef41Sopenharmony_ci 'GET /flag HTTP/1.1', 221cb0ef41Sopenharmony_ci 'Host: 127.0.0.1', 231cb0ef41Sopenharmony_ci '', 241cb0ef41Sopenharmony_ci '', 251cb0ef41Sopenharmony_ci ].join('\r\n'); 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ci const server = http.createServer(common.mustNotCall((req, res) => { 281cb0ef41Sopenharmony_ci res.end(); 291cb0ef41Sopenharmony_ci }, 1)); 301cb0ef41Sopenharmony_ci 311cb0ef41Sopenharmony_ci server.listen(0, common.mustSucceed(() => { 321cb0ef41Sopenharmony_ci const client = net.connect(server.address().port, 'localhost'); 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ci let response = ''; 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ci // Verify that the server listener is never called 371cb0ef41Sopenharmony_ci 381cb0ef41Sopenharmony_ci client.on('data', common.mustCall((chunk) => { 391cb0ef41Sopenharmony_ci response += chunk; 401cb0ef41Sopenharmony_ci })); 411cb0ef41Sopenharmony_ci 421cb0ef41Sopenharmony_ci client.setEncoding('utf8'); 431cb0ef41Sopenharmony_ci client.on('error', common.mustNotCall()); 441cb0ef41Sopenharmony_ci client.on('end', common.mustCall(() => { 451cb0ef41Sopenharmony_ci assert.strictEqual( 461cb0ef41Sopenharmony_ci response, 471cb0ef41Sopenharmony_ci 'HTTP/1.1 400 Bad Request\r\nConnection: close\r\n\r\n' 481cb0ef41Sopenharmony_ci ); 491cb0ef41Sopenharmony_ci server.close(); 501cb0ef41Sopenharmony_ci })); 511cb0ef41Sopenharmony_ci client.write(msg); 521cb0ef41Sopenharmony_ci client.resume(); 531cb0ef41Sopenharmony_ci })); 541cb0ef41Sopenharmony_ci} 551cb0ef41Sopenharmony_ci 561cb0ef41Sopenharmony_ci{ 571cb0ef41Sopenharmony_ci const msg = [ 581cb0ef41Sopenharmony_ci 'POST / HTTP/1.1', 591cb0ef41Sopenharmony_ci 'Host: 127.0.0.1', 601cb0ef41Sopenharmony_ci 'Transfer-Encoding: chunked', 611cb0ef41Sopenharmony_ci ' , chunked-false', 621cb0ef41Sopenharmony_ci 'Connection: upgrade', 631cb0ef41Sopenharmony_ci '', 641cb0ef41Sopenharmony_ci '1', 651cb0ef41Sopenharmony_ci 'A', 661cb0ef41Sopenharmony_ci '0', 671cb0ef41Sopenharmony_ci '', 681cb0ef41Sopenharmony_ci 'GET /flag HTTP/1.1', 691cb0ef41Sopenharmony_ci 'Host: 127.0.0.1', 701cb0ef41Sopenharmony_ci '', 711cb0ef41Sopenharmony_ci '', 721cb0ef41Sopenharmony_ci ].join('\r\n'); 731cb0ef41Sopenharmony_ci 741cb0ef41Sopenharmony_ci const server = http.createServer(common.mustNotCall()); 751cb0ef41Sopenharmony_ci 761cb0ef41Sopenharmony_ci server.listen(0, common.mustSucceed(() => { 771cb0ef41Sopenharmony_ci const client = net.connect(server.address().port, 'localhost'); 781cb0ef41Sopenharmony_ci 791cb0ef41Sopenharmony_ci client.on('end', common.mustCall(function() { 801cb0ef41Sopenharmony_ci server.close(); 811cb0ef41Sopenharmony_ci })); 821cb0ef41Sopenharmony_ci 831cb0ef41Sopenharmony_ci client.write(msg); 841cb0ef41Sopenharmony_ci client.resume(); 851cb0ef41Sopenharmony_ci })); 861cb0ef41Sopenharmony_ci} 87