aboutsummaryrefslogtreecommitdiff
path: root/test/parallel/test-http-slow-headers.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/parallel/test-http-slow-headers.js')
-rw-r--r--test/parallel/test-http-slow-headers.js50
1 files changed, 50 insertions, 0 deletions
diff --git a/test/parallel/test-http-slow-headers.js b/test/parallel/test-http-slow-headers.js
new file mode 100644
index 0000000000..6da11465da
--- /dev/null
+++ b/test/parallel/test-http-slow-headers.js
@@ -0,0 +1,50 @@
+'use strict';
+
+const common = require('../common');
+const assert = require('assert');
+const { createServer } = require('http');
+const { connect } = require('net');
+const { finished } = require('stream');
+
+// This test validates that the 'timeout' event fires
+// after server.headersTimeout.
+
+const headers =
+ 'GET / HTTP/1.1\r\n' +
+ 'Host: localhost\r\n' +
+ 'Agent: node\r\n';
+
+const server = createServer(common.mustNotCall());
+let sendCharEvery = 1000;
+
+// 40 seconds is the default
+assert.strictEqual(server.headersTimeout, 40 * 1000);
+
+// Pass a REAL env variable to shortening up the default
+// value which is 40s otherwise this is useful for manual
+// testing
+if (!process.env.REAL) {
+ sendCharEvery = common.platformTimeout(10);
+ server.headersTimeout = 2 * sendCharEvery;
+}
+
+server.once('timeout', common.mustCall((socket) => {
+ socket.destroy();
+}));
+
+server.listen(0, common.mustCall(() => {
+ const client = connect(server.address().port);
+ client.write(headers);
+ client.write('X-CRASH: ');
+
+ const interval = setInterval(() => {
+ client.write('a');
+ }, sendCharEvery);
+
+ client.resume();
+
+ finished(client, common.mustCall((err) => {
+ clearInterval(interval);
+ server.close();
+ }));
+}));