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.headersTimeout if the client 101cb0ef41Sopenharmony_ci// pauses before start sending the request. 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_cilet sendDelayedRequestHeaders; 131cb0ef41Sopenharmony_ciconst headersTimeout = common.platformTimeout(2000); 141cb0ef41Sopenharmony_ciconst server = createServer({ 151cb0ef41Sopenharmony_ci headersTimeout, 161cb0ef41Sopenharmony_ci requestTimeout: 0, 171cb0ef41Sopenharmony_ci keepAliveTimeout: 0, 181cb0ef41Sopenharmony_ci connectionsCheckingInterval: headersTimeout / 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.headersTimeout, headersTimeout); 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ci// Check that timeout event is not triggered 281cb0ef41Sopenharmony_ciserver.once('timeout', common.mustNotCall((socket) => { 291cb0ef41Sopenharmony_ci socket.destroy(); 301cb0ef41Sopenharmony_ci})); 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_ciserver.listen(0, common.mustCall(() => { 331cb0ef41Sopenharmony_ci const client = connect(server.address().port); 341cb0ef41Sopenharmony_ci let response = ''; 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ci client.setEncoding('utf8'); 371cb0ef41Sopenharmony_ci client.on('data', common.mustCall((chunk) => { 381cb0ef41Sopenharmony_ci response += chunk; 391cb0ef41Sopenharmony_ci })); 401cb0ef41Sopenharmony_ci 411cb0ef41Sopenharmony_ci const errOrEnd = common.mustSucceed(function(err) { 421cb0ef41Sopenharmony_ci assert.strictEqual( 431cb0ef41Sopenharmony_ci response, 441cb0ef41Sopenharmony_ci 'HTTP/1.1 408 Request Timeout\r\nConnection: close\r\n\r\n' 451cb0ef41Sopenharmony_ci ); 461cb0ef41Sopenharmony_ci server.close(); 471cb0ef41Sopenharmony_ci }); 481cb0ef41Sopenharmony_ci 491cb0ef41Sopenharmony_ci client.on('end', errOrEnd); 501cb0ef41Sopenharmony_ci client.on('error', errOrEnd); 511cb0ef41Sopenharmony_ci 521cb0ef41Sopenharmony_ci client.resume(); 531cb0ef41Sopenharmony_ci 541cb0ef41Sopenharmony_ci sendDelayedRequestHeaders = common.mustCall(() => { 551cb0ef41Sopenharmony_ci setTimeout(() => { 561cb0ef41Sopenharmony_ci client.write('POST / HTTP/1.1\r\n'); 571cb0ef41Sopenharmony_ci client.write('Content-Length: 20\r\n'); 581cb0ef41Sopenharmony_ci client.write('Connection: close\r\n\r\n'); 591cb0ef41Sopenharmony_ci client.write('12345678901234567890\r\n\r\n'); 601cb0ef41Sopenharmony_ci }, common.platformTimeout(headersTimeout * 2)).unref(); 611cb0ef41Sopenharmony_ci }); 621cb0ef41Sopenharmony_ci})); 63