11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ciconst http = require('http'); 51cb0ef41Sopenharmony_ciconst MakeDuplexPair = require('../common/duplexpair'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ci// Test that setting the `maxHeaderSize` option works on a per-stream-basis. 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ci// Test 1: The server sends an invalid header. 101cb0ef41Sopenharmony_ci{ 111cb0ef41Sopenharmony_ci const { clientSide, serverSide } = MakeDuplexPair(); 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ci const req = http.request({ 141cb0ef41Sopenharmony_ci createConnection: common.mustCall(() => clientSide), 151cb0ef41Sopenharmony_ci insecureHTTPParser: true 161cb0ef41Sopenharmony_ci }, common.mustCall((res) => { 171cb0ef41Sopenharmony_ci assert.strictEqual(res.headers.hello, 'foo\x08foo'); 181cb0ef41Sopenharmony_ci res.resume(); // We don’t actually care about contents. 191cb0ef41Sopenharmony_ci res.on('end', common.mustCall()); 201cb0ef41Sopenharmony_ci })); 211cb0ef41Sopenharmony_ci req.end(); 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ci serverSide.resume(); // Dump the request 241cb0ef41Sopenharmony_ci serverSide.end('HTTP/1.1 200 OK\r\n' + 251cb0ef41Sopenharmony_ci 'Hello: foo\x08foo\r\n' + 261cb0ef41Sopenharmony_ci 'Content-Length: 0\r\n' + 271cb0ef41Sopenharmony_ci '\r\n\r\n'); 281cb0ef41Sopenharmony_ci} 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ci// Test 2: The same as Test 1 except without the option, to make sure it fails. 311cb0ef41Sopenharmony_ci{ 321cb0ef41Sopenharmony_ci const { clientSide, serverSide } = MakeDuplexPair(); 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ci const req = http.request({ 351cb0ef41Sopenharmony_ci createConnection: common.mustCall(() => clientSide) 361cb0ef41Sopenharmony_ci }, common.mustNotCall()); 371cb0ef41Sopenharmony_ci req.end(); 381cb0ef41Sopenharmony_ci req.on('error', common.mustCall()); 391cb0ef41Sopenharmony_ci 401cb0ef41Sopenharmony_ci serverSide.resume(); // Dump the request 411cb0ef41Sopenharmony_ci serverSide.end('HTTP/1.1 200 OK\r\n' + 421cb0ef41Sopenharmony_ci 'Hello: foo\x08foo\r\n' + 431cb0ef41Sopenharmony_ci 'Content-Length: 0\r\n' + 441cb0ef41Sopenharmony_ci '\r\n\r\n'); 451cb0ef41Sopenharmony_ci} 461cb0ef41Sopenharmony_ci 471cb0ef41Sopenharmony_ci// Test 3: The client sends an invalid header. 481cb0ef41Sopenharmony_ci{ 491cb0ef41Sopenharmony_ci const testData = 'Hello, World!\n'; 501cb0ef41Sopenharmony_ci const server = http.createServer( 511cb0ef41Sopenharmony_ci { insecureHTTPParser: true }, 521cb0ef41Sopenharmony_ci common.mustCall((req, res) => { 531cb0ef41Sopenharmony_ci res.statusCode = 200; 541cb0ef41Sopenharmony_ci res.setHeader('Content-Type', 'text/plain'); 551cb0ef41Sopenharmony_ci res.end(testData); 561cb0ef41Sopenharmony_ci })); 571cb0ef41Sopenharmony_ci 581cb0ef41Sopenharmony_ci server.on('clientError', common.mustNotCall()); 591cb0ef41Sopenharmony_ci 601cb0ef41Sopenharmony_ci const { clientSide, serverSide } = MakeDuplexPair(); 611cb0ef41Sopenharmony_ci serverSide.server = server; 621cb0ef41Sopenharmony_ci server.emit('connection', serverSide); 631cb0ef41Sopenharmony_ci 641cb0ef41Sopenharmony_ci clientSide.write('GET / HTTP/1.1\r\n' + 651cb0ef41Sopenharmony_ci 'Hello: foo\x08foo\r\n' + 661cb0ef41Sopenharmony_ci '\r\n\r\n'); 671cb0ef41Sopenharmony_ci} 681cb0ef41Sopenharmony_ci 691cb0ef41Sopenharmony_ci// Test 4: The same as Test 3 except without the option, to make sure it fails. 701cb0ef41Sopenharmony_ci{ 711cb0ef41Sopenharmony_ci const server = http.createServer(common.mustNotCall()); 721cb0ef41Sopenharmony_ci 731cb0ef41Sopenharmony_ci server.on('clientError', common.mustCall()); 741cb0ef41Sopenharmony_ci 751cb0ef41Sopenharmony_ci const { clientSide, serverSide } = MakeDuplexPair(); 761cb0ef41Sopenharmony_ci serverSide.server = server; 771cb0ef41Sopenharmony_ci server.emit('connection', serverSide); 781cb0ef41Sopenharmony_ci 791cb0ef41Sopenharmony_ci clientSide.write('GET / HTTP/1.1\r\n' + 801cb0ef41Sopenharmony_ci 'Hello: foo\x08foo\r\n' + 811cb0ef41Sopenharmony_ci '\r\n\r\n'); 821cb0ef41Sopenharmony_ci} 831cb0ef41Sopenharmony_ci 841cb0ef41Sopenharmony_ci// Test 5: Invalid argument type 851cb0ef41Sopenharmony_ci{ 861cb0ef41Sopenharmony_ci assert.throws( 871cb0ef41Sopenharmony_ci () => http.request({ insecureHTTPParser: 0 }, common.mustNotCall()), 881cb0ef41Sopenharmony_ci common.expectsError({ 891cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_TYPE', 901cb0ef41Sopenharmony_ci message: 'The "options.insecureHTTPParser" property must be of' + 911cb0ef41Sopenharmony_ci ' type boolean. Received type number (0)' 921cb0ef41Sopenharmony_ci }) 931cb0ef41Sopenharmony_ci ); 941cb0ef41Sopenharmony_ci} 95