11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciconst assert = require('assert'); 51cb0ef41Sopenharmony_ciconst { createServer } = require('http'); 61cb0ef41Sopenharmony_ciconst { connect } = require('net'); 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci// This test validates that the server returns 408 91cb0ef41Sopenharmony_ci// after server.requestTimeout if the client 101cb0ef41Sopenharmony_ci// pauses sending in the middle of a header. 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_cilet sendDelayedRequestHeaders; 131cb0ef41Sopenharmony_ciconst requestTimeout = common.platformTimeout(2000); 141cb0ef41Sopenharmony_ciconst server = createServer({ 151cb0ef41Sopenharmony_ci headersTimeout: 0, 161cb0ef41Sopenharmony_ci requestTimeout, 171cb0ef41Sopenharmony_ci keepAliveTimeout: 0, 181cb0ef41Sopenharmony_ci connectionsCheckingInterval: requestTimeout / 4, 191cb0ef41Sopenharmony_ci}, common.mustNotCall()); 201cb0ef41Sopenharmony_ciserver.on('connection', common.mustCall(() => { 211cb0ef41Sopenharmony_ci assert.strictEqual(typeof sendDelayedRequestHeaders, 'function'); 221cb0ef41Sopenharmony_ci sendDelayedRequestHeaders(); 231cb0ef41Sopenharmony_ci})); 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ciassert.strictEqual(server.requestTimeout, requestTimeout); 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ciserver.listen(0, common.mustCall(() => { 281cb0ef41Sopenharmony_ci const client = connect(server.address().port); 291cb0ef41Sopenharmony_ci let response = ''; 301cb0ef41Sopenharmony_ci 311cb0ef41Sopenharmony_ci client.setEncoding('utf8'); 321cb0ef41Sopenharmony_ci client.on('data', common.mustCall((chunk) => { 331cb0ef41Sopenharmony_ci response += chunk; 341cb0ef41Sopenharmony_ci })); 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ci const errOrEnd = common.mustSucceed(function(err) { 371cb0ef41Sopenharmony_ci assert.strictEqual( 381cb0ef41Sopenharmony_ci response, 391cb0ef41Sopenharmony_ci 'HTTP/1.1 408 Request Timeout\r\nConnection: close\r\n\r\n' 401cb0ef41Sopenharmony_ci ); 411cb0ef41Sopenharmony_ci server.close(); 421cb0ef41Sopenharmony_ci }); 431cb0ef41Sopenharmony_ci 441cb0ef41Sopenharmony_ci client.on('end', errOrEnd); 451cb0ef41Sopenharmony_ci client.on('error', errOrEnd); 461cb0ef41Sopenharmony_ci 471cb0ef41Sopenharmony_ci client.resume(); 481cb0ef41Sopenharmony_ci client.write('GET / HTTP/1.1\r\n'); 491cb0ef41Sopenharmony_ci client.write('Connection: close\r\n'); 501cb0ef41Sopenharmony_ci client.write('X-CRASH: '); 511cb0ef41Sopenharmony_ci 521cb0ef41Sopenharmony_ci sendDelayedRequestHeaders = common.mustCall(() => { 531cb0ef41Sopenharmony_ci setTimeout(() => { 541cb0ef41Sopenharmony_ci client.write('1234567890\r\n\r\n'); 551cb0ef41Sopenharmony_ci }, common.platformTimeout(requestTimeout * 2)).unref(); 561cb0ef41Sopenharmony_ci }); 571cb0ef41Sopenharmony_ci})); 58