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 before start sending the body. 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_cilet sendDelayedRequestBody; 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.mustCall((req, res) => { 201cb0ef41Sopenharmony_ci let body = ''; 211cb0ef41Sopenharmony_ci req.setEncoding('utf-8'); 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ci req.on('data', (chunk) => { 241cb0ef41Sopenharmony_ci body += chunk; 251cb0ef41Sopenharmony_ci }); 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ci req.on('end', () => { 281cb0ef41Sopenharmony_ci res.writeHead(200, { 'Content-Type': 'text/plain' }); 291cb0ef41Sopenharmony_ci res.write(body); 301cb0ef41Sopenharmony_ci res.end(); 311cb0ef41Sopenharmony_ci }); 321cb0ef41Sopenharmony_ci 331cb0ef41Sopenharmony_ci assert.strictEqual(typeof sendDelayedRequestBody, 'function'); 341cb0ef41Sopenharmony_ci sendDelayedRequestBody(); 351cb0ef41Sopenharmony_ci})); 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ciassert.strictEqual(server.requestTimeout, requestTimeout); 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ciserver.listen(0, common.mustCall(() => { 401cb0ef41Sopenharmony_ci const client = connect(server.address().port); 411cb0ef41Sopenharmony_ci let response = ''; 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_ci client.setEncoding('utf8'); 441cb0ef41Sopenharmony_ci client.on('data', common.mustCall((chunk) => { 451cb0ef41Sopenharmony_ci response += chunk; 461cb0ef41Sopenharmony_ci })); 471cb0ef41Sopenharmony_ci 481cb0ef41Sopenharmony_ci client.resume(); 491cb0ef41Sopenharmony_ci client.write('POST / HTTP/1.1\r\n'); 501cb0ef41Sopenharmony_ci client.write('Content-Length: 20\r\n'); 511cb0ef41Sopenharmony_ci client.write('Connection: close\r\n'); 521cb0ef41Sopenharmony_ci client.write('\r\n'); 531cb0ef41Sopenharmony_ci 541cb0ef41Sopenharmony_ci sendDelayedRequestBody = common.mustCall(() => { 551cb0ef41Sopenharmony_ci setTimeout(() => { 561cb0ef41Sopenharmony_ci client.write('12345678901234567890\r\n\r\n'); 571cb0ef41Sopenharmony_ci }, common.platformTimeout(requestTimeout * 2)).unref(); 581cb0ef41Sopenharmony_ci }); 591cb0ef41Sopenharmony_ci 601cb0ef41Sopenharmony_ci const errOrEnd = common.mustSucceed(function(err) { 611cb0ef41Sopenharmony_ci assert.strictEqual( 621cb0ef41Sopenharmony_ci response, 631cb0ef41Sopenharmony_ci 'HTTP/1.1 408 Request Timeout\r\nConnection: close\r\n\r\n' 641cb0ef41Sopenharmony_ci ); 651cb0ef41Sopenharmony_ci server.close(); 661cb0ef41Sopenharmony_ci }); 671cb0ef41Sopenharmony_ci 681cb0ef41Sopenharmony_ci client.on('end', errOrEnd); 691cb0ef41Sopenharmony_ci client.on('error', errOrEnd); 701cb0ef41Sopenharmony_ci})); 71