node/test/parallel/test-http-server-headers-timeout-interrupted-headers.js
Luigi Pinca 50d405a2b6
Some checks failed
Coverage Linux (without intl) / coverage-linux-without-intl (push) Waiting to run
Coverage Linux / coverage-linux (push) Waiting to run
Coverage Windows / coverage-windows (push) Waiting to run
Test and upload documentation to artifacts / build-docs (push) Waiting to run
Linters / lint-addon-docs (push) Waiting to run
Linters / lint-cpp (push) Waiting to run
Linters / format-cpp (push) Waiting to run
Linters / lint-js-and-md (push) Waiting to run
Linters / lint-py (push) Waiting to run
Linters / lint-yaml (push) Waiting to run
Linters / lint-sh (push) Waiting to run
Linters / lint-codeowners (push) Waiting to run
Linters / lint-pr-url (push) Waiting to run
Linters / lint-readme (push) Waiting to run
Notify on Push / Notify on Force Push on `main` (push) Waiting to run
Notify on Push / Notify on Push on `main` that lacks metadata (push) Waiting to run
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
test: reduce number of written chunks
Reduce chances of write errors while the request is sent.

Refs: https://github.com/nodejs/node/pull/56756
PR-URL: https://github.com/nodejs/node/pull/56757
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Stefan Stojanovic <stefan.stojanovic@janeasystems.com>
2025-01-27 10:35:11 +00:00

67 lines
1.7 KiB
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const { createServer } = require('http');
const { connect } = require('net');
// This test validates that the server returns 408
// after server.headersTimeout if the client
// pauses sending in the middle of a header.
let sendDelayedRequestHeaders;
const headersTimeout = common.platformTimeout(2000);
const server = createServer({
headersTimeout,
requestTimeout: 0,
keepAliveTimeout: 0,
connectionsCheckingInterval: headersTimeout / 4,
}, common.mustNotCall());
server.on('connection', common.mustCall(() => {
assert.strictEqual(typeof sendDelayedRequestHeaders, 'function');
sendDelayedRequestHeaders();
}));
assert.strictEqual(server.headersTimeout, headersTimeout);
// Check that timeout event is not triggered
server.once('timeout', common.mustNotCall((socket) => {
socket.destroy();
}));
server.listen(0, common.mustCall(() => {
const client = connect(server.address().port);
let response = '';
client.setEncoding('utf8');
client.on('data', common.mustCall((chunk) => {
response += chunk;
}));
client.on('error', () => {
// Ignore errors like 'write EPIPE' that might occur while the request is
// sent.
});
client.on('close', common.mustCall(() => {
assert.strictEqual(
response,
'HTTP/1.1 408 Request Timeout\r\nConnection: close\r\n\r\n'
);
server.close();
}));
client.resume();
client.write(
'GET / HTTP/1.1\r\n' +
'Connection: close\r\n' +
'X-CRASH: '
);
sendDelayedRequestHeaders = common.mustCall(() => {
setTimeout(() => {
client.write('1234567890\r\n\r\n');
}, common.platformTimeout(headersTimeout * 2)).unref();
});
}));