mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 21:19:50 +01:00
febb5390aa
Let’s not have bad examples in our test suite and instead use the proper way of converting stream data to UTF-8 (i.e. `stream.setEncoding('utf8')`) in all places. PR-URL: https://github.com/nodejs/node/pull/43731 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
58 lines
1.6 KiB
JavaScript
58 lines
1.6 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.requestTimeout if the client
|
|
// pauses before start sending the request.
|
|
|
|
let sendDelayedRequestHeaders;
|
|
const requestTimeout = common.platformTimeout(2000);
|
|
const server = createServer({
|
|
headersTimeout: 0,
|
|
requestTimeout,
|
|
keepAliveTimeout: 0,
|
|
connectionsCheckingInterval: requestTimeout / 4,
|
|
}, common.mustNotCall());
|
|
server.on('connection', common.mustCall(() => {
|
|
assert.strictEqual(typeof sendDelayedRequestHeaders, 'function');
|
|
sendDelayedRequestHeaders();
|
|
}));
|
|
|
|
assert.strictEqual(server.requestTimeout, requestTimeout);
|
|
|
|
server.listen(0, common.mustCall(() => {
|
|
const client = connect(server.address().port);
|
|
let response = '';
|
|
|
|
client.setEncoding('utf8');
|
|
client.on('data', common.mustCall((chunk) => {
|
|
response += chunk;
|
|
}));
|
|
|
|
const errOrEnd = common.mustSucceed(function(err) {
|
|
assert.strictEqual(
|
|
response,
|
|
'HTTP/1.1 408 Request Timeout\r\nConnection: close\r\n\r\n'
|
|
);
|
|
server.close();
|
|
});
|
|
|
|
client.on('end', errOrEnd);
|
|
client.on('error', errOrEnd);
|
|
|
|
client.resume();
|
|
|
|
sendDelayedRequestHeaders = common.mustCall(() => {
|
|
setTimeout(() => {
|
|
client.write('POST / HTTP/1.1\r\n');
|
|
client.write('Content-Length: 20\r\n');
|
|
client.write('Connection: close\r\n\r\n');
|
|
client.write('12345678901234567890\r\n\r\n');
|
|
}, common.platformTimeout(requestTimeout * 2)).unref();
|
|
});
|
|
}));
|