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_cifunction serverHandler(server, msg) { 101cb0ef41Sopenharmony_ci const client = net.connect(server.address().port, 'localhost'); 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ci let response = ''; 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ci client.on('data', common.mustCall((chunk) => { 151cb0ef41Sopenharmony_ci response += chunk; 161cb0ef41Sopenharmony_ci })); 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ci client.setEncoding('utf8'); 191cb0ef41Sopenharmony_ci client.on('error', common.mustNotCall()); 201cb0ef41Sopenharmony_ci client.on('end', common.mustCall(() => { 211cb0ef41Sopenharmony_ci assert.strictEqual( 221cb0ef41Sopenharmony_ci response, 231cb0ef41Sopenharmony_ci 'HTTP/1.1 400 Bad Request\r\nConnection: close\r\n\r\n' 241cb0ef41Sopenharmony_ci ); 251cb0ef41Sopenharmony_ci server.close(); 261cb0ef41Sopenharmony_ci })); 271cb0ef41Sopenharmony_ci client.write(msg); 281cb0ef41Sopenharmony_ci client.resume(); 291cb0ef41Sopenharmony_ci} 301cb0ef41Sopenharmony_ci 311cb0ef41Sopenharmony_ci{ 321cb0ef41Sopenharmony_ci const msg = [ 331cb0ef41Sopenharmony_ci 'GET / HTTP/1.1', 341cb0ef41Sopenharmony_ci 'Host: localhost', 351cb0ef41Sopenharmony_ci 'Dummy: x\nContent-Length: 23', 361cb0ef41Sopenharmony_ci '', 371cb0ef41Sopenharmony_ci 'GET / HTTP/1.1', 381cb0ef41Sopenharmony_ci 'Dummy: GET /admin HTTP/1.1', 391cb0ef41Sopenharmony_ci 'Host: localhost', 401cb0ef41Sopenharmony_ci '', 411cb0ef41Sopenharmony_ci '', 421cb0ef41Sopenharmony_ci ].join('\r\n'); 431cb0ef41Sopenharmony_ci 441cb0ef41Sopenharmony_ci const server = http.createServer(common.mustNotCall()); 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_ci server.listen(0, common.mustSucceed(serverHandler.bind(null, server, msg))); 471cb0ef41Sopenharmony_ci} 481cb0ef41Sopenharmony_ci 491cb0ef41Sopenharmony_ci{ 501cb0ef41Sopenharmony_ci const msg = [ 511cb0ef41Sopenharmony_ci 'POST / HTTP/1.1', 521cb0ef41Sopenharmony_ci 'Host: localhost', 531cb0ef41Sopenharmony_ci 'x:x\nTransfer-Encoding: chunked', 541cb0ef41Sopenharmony_ci '', 551cb0ef41Sopenharmony_ci '1', 561cb0ef41Sopenharmony_ci 'A', 571cb0ef41Sopenharmony_ci '0', 581cb0ef41Sopenharmony_ci '', 591cb0ef41Sopenharmony_ci '', 601cb0ef41Sopenharmony_ci ].join('\r\n'); 611cb0ef41Sopenharmony_ci 621cb0ef41Sopenharmony_ci const server = http.createServer(common.mustNotCall()); 631cb0ef41Sopenharmony_ci 641cb0ef41Sopenharmony_ci server.listen(0, common.mustSucceed(serverHandler.bind(null, server, msg))); 651cb0ef41Sopenharmony_ci} 661cb0ef41Sopenharmony_ci 671cb0ef41Sopenharmony_ci{ 681cb0ef41Sopenharmony_ci const msg = [ 691cb0ef41Sopenharmony_ci 'POST / HTTP/1.1', 701cb0ef41Sopenharmony_ci 'Host: localhost', 711cb0ef41Sopenharmony_ci 'x:\nTransfer-Encoding: chunked', 721cb0ef41Sopenharmony_ci '', 731cb0ef41Sopenharmony_ci '1', 741cb0ef41Sopenharmony_ci 'A', 751cb0ef41Sopenharmony_ci '0', 761cb0ef41Sopenharmony_ci '', 771cb0ef41Sopenharmony_ci '', 781cb0ef41Sopenharmony_ci ].join('\r\n'); 791cb0ef41Sopenharmony_ci 801cb0ef41Sopenharmony_ci const server = http.createServer(common.mustNotCall()); 811cb0ef41Sopenharmony_ci 821cb0ef41Sopenharmony_ci server.listen(0, common.mustSucceed(serverHandler.bind(null, server, msg))); 831cb0ef41Sopenharmony_ci} 84