10BC0
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5dab101 commit 069b6e1Copy full SHA for 069b6e1
doc/api/http.md
@@ -943,7 +943,7 @@ added: v0.1.90
943
944
Stops the server from accepting new connections. See [`net.Server.close()`][].
945
946
-### server.listen()
+### `server.listen()`
947
948
Starts the HTTP server listening for connections.
949
This method is identical to [`server.listen()`][] from [`net.Server`][].
@@ -984,6 +984,8 @@ event is emitted on the server object, and (by default) the socket is destroyed.
984
See [server.timeout][] for more information on how timeout behaviour can be
985
customised.
986
987
+A value of `0` will disable the HTTP headers timeout check.
988
+
989
### server.setTimeout([msecs][, callback])
990
<!-- YAML
991
added: v0.9.12
lib/_http_server.js
@@ -501,8 +501,12 @@ function onParserExecute(server, socket, parser, state, ret) {
501
502
// If we have not parsed the headers, destroy the socket
503
// after server.headersTimeout to protect from DoS attacks.
504
- // start === 0 means that we have parsed headers.
505
- if (start !== 0 && nowDate() - start > server.headersTimeout) {
+ // start === 0 means that we have parsed headers, while
+ // server.headersTimeout === 0 means user disabled this check.
506
+ if (
507
+ start !== 0 && server.headersTimeout &&
508
+ nowDate() - start > server.headersTimeout
509
+ ) {
510
const serverTimeout = server.emit('timeout', socket);
511
512
if (!serverTimeout)
test/parallel/test-http-server-disabled-headers-timeout.js
@@ -0,0 +1,49 @@
1
+'use strict';
2
3
+const common = require('../common');
4
+const assert = require('assert');
5
+const { createServer } = require('http');
6
+const { connect } = require('net');
7
8
+// This test verifies that it is possible to disable
9
+// headersTimeout by setting it to zero.
10
11
+const server = createServer(common.mustCall((req, res) => {
12
+ res.writeHead(200);
13
+ res.end('OK');
14
+}));
15
16
+server.headersTimeout = 0;
17
18
+server.once('timeout', common.mustNotCall((socket) => {
19
+ socket.destroy();
20
21
22
+server.listen(0, common.mustCall(() => {
23
+ const client = connect(server.address().port);
24
+ let response = '';
25
26
+ client.resume();
27
+ client.write('GET / HTTP/1.1\r\nConnection: close\r\n');
28
29
+ // All the timeouts below must be greater than a second, otherwise
30
+ // headersTimeout won't be triggered anyway as the current date is cached
31
+ // for a second in HTTP internals.
32
+ setTimeout(() => {
33
+ client.write('X-Crash: Ab: 456\r\n');
34
+ }, common.platformTimeout(1100)).unref();
35
36
37
+ client.write('\r\n');
38
+ }, common.platformTimeout(1200)).unref();
39
40
+ client.on('data', (chunk) => {
41
+ response += chunk.toString('utf-8');
42
+ });
43
44
+ client.on('end', common.mustCall(() => {
45
+ assert.strictEqual(response.split('\r\n').shift(), 'HTTP/1.1 200 OK');
46
+ client.end();
47
+ server.close();
48
+ }));
49