0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-http-server-keep-alive-timeout-slow-server.js
Alexey Orlenko d71718db6a
http: fix timeout reset after keep-alive timeout
Fix the logic of resetting the socket timeout of keep-alive HTTP
connections and add two tests:

* `test-http-server-keep-alive-timeout-slow-server` is a regression test
  for GH-13391.  It ensures that the server-side keep-alive timeout will
  not fire during processing of a request.

* `test-http-server-keep-alive-timeout-slow-client-headers` ensures that
  the regular socket timeout is restored as soon as a client starts
  sending a new request, not as soon as the whole message is received,
  so that the keep-alive timeout will not fire while, e.g., the client
  is sending large cookies.

Refs: https://github.com/nodejs/node/pull/2534
Fixes: https://github.com/nodejs/node/issues/13391
PR-URL: https://github.com/nodejs/node/pull/13549
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
2017-06-13 07:42:11 +03:00

51 lines
1.0 KiB
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const http = require('http');
const server = http.createServer(common.mustCall((req, res) => {
if (req.url === '/first') {
res.end('ok');
return;
}
setTimeout(() => {
res.end('ok');
}, common.platformTimeout(500));
}, 2));
server.keepAliveTimeout = common.platformTimeout(200);
const agent = new http.Agent({
keepAlive: true,
maxSockets: 1
});
function request(path, callback) {
const port = server.address().port;
const req = http.request({ agent, path, port }, common.mustCall((res) => {
assert.strictEqual(res.statusCode, 200);
res.setEncoding('utf8');
let result = '';
res.on('data', (chunk) => {
result += chunk;
});
res.on('end', common.mustCall(() => {
assert.strictEqual(result, 'ok');
callback();
}));
}));
req.end();
}
server.listen(0, common.mustCall(() => {
request('/first', () => {
request('/second', () => {
server.close();
});
});
}));