| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9d6af7d commit 3caa2c1
33 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,10 +32,11 @@ function main({ len, n, c, duration }) { | |||
| 32 | 32 | send(n); | |
| 33 | 33 | }); | |
| 34 | 34 | ||
| 35 | - server.listen(common.PORT, () => { | ||
| 35 | + server.listen(0, () => { | ||
| 36 | 36 | bench.http({ | |
| 37 | 37 | connections: c, | |
| 38 | - duration | ||
| 38 | + duration, | ||
| 39 | + port: server.address().port, | ||
| 39 | 40 | }, () => { | |
| 40 | 41 | server.close(); | |
| 41 | 42 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,24 +32,24 @@ function main({ dur, len, type, method }) { | |||
| 32 | 32 | headers: { 'Connection': 'keep-alive', 'Transfer-Encoding': 'chunked' }, | |
| 33 | 33 | agent: new http.Agent({ maxSockets: 1 }), | |
| 34 | 34 | host: '127.0.0.1', | |
| 35 | - port: common.PORT, | ||
| 36 | 35 | path: '/', | |
| 37 | 36 | method: 'POST' | |
| 38 | 37 | }; | |
| 39 | 38 | ||
| 40 | 39 | const server = http.createServer((req, res) => { | |
| 41 | 40 | res.end(); | |
| 42 | 41 | }); | |
| 43 | - server.listen(options.port, options.host, () => { | ||
| 42 | + server.listen(0, options.host, () => { | ||
| 44 | 43 | setTimeout(done, dur * 1000); | |
| 45 | 44 | bench.start(); | |
| 46 | - pummel(); | ||
| 45 | + pummel(server.address().port); | ||
| 47 | 46 | }); | |
| 48 | 47 | ||
| 49 | - function pummel() { | ||
| 48 | + function pummel(port) { | ||
| 49 | + options.port = port; | ||
| 50 | 50 | const req = http.request(options, (res) => { | |
| 51 | 51 | nreqs++; | |
| 52 | - pummel(); // Line up next request. | ||
| 52 | + pummel(port); // Line up next request. | ||
| 53 | 53 | res.resume(); | |
| 54 | 54 | }); | |
| 55 | 55 | if (method === 'write') { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -48,10 +48,11 @@ function main({ len, type, method, c, duration }) { | |||
| 48 | 48 | fn(res); | |
| 49 | 49 | }); | |
| 50 | 50 | ||
| 51 | - server.listen(common.PORT, () => { | ||
| 51 | + server.listen(0, () => { | ||
| 52 | 52 | bench.http({ | |
| 53 | 53 | connections: c, | |
| 54 | - duration | ||
| 54 | + duration, | ||
| 55 | + port: server.address().port, | ||
| 55 | 56 | }, () => { | |
| 56 | 57 | server.close(); | |
| 57 | 58 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,11 +27,12 @@ function main({ len, n, duration }) { | |||
| 27 | 27 | res.writeHead(200, headers); | |
| 28 | 28 | res.end(); | |
| 29 | 29 | }); | |
| 30 | - server.listen(common.PORT, () => { | ||
| 30 | + server.listen(0, () => { | ||
| 31 | 31 | bench.http({ | |
| 32 | 32 | path: '/', | |
| 33 | 33 | connections: 10, | |
| 34 | - duration | ||
| 34 | + duration, | ||
| 35 | + port: server.address().port, | ||
| 35 | 36 | }, () => { | |
| 36 | 37 | server.close(); | |
| 37 | 38 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,7 +14,7 @@ function main({ connections, headers, w, duration }) { | |||
| 14 | 14 | res.end(); | |
| 15 | 15 | }); | |
| 16 | 16 | ||
| 17 | - server.listen(common.PORT, () => { | ||
| 17 | + server.listen(0, () => { | ||
| 18 | 18 | const headers = { | |
| 19 | 19 | 'Content-Type': 'text/plain', | |
| 20 | 20 | 'Accept': 'text/plain', | |
@@ -34,7 +34,8 @@ function main({ connections, headers, w, duration }) { | |||
| 34 | 34 | path: '/', | |
| 35 | 35 | connections, | |
| 36 | 36 | headers, | |
| 37 | - duration | ||
| 37 | + duration, | ||
| 38 | + port: server.address().port, | ||
| 38 | 39 | }, () => { | |
| 39 | 40 | server.close(); | |
| 40 | 41 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,5 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | const common = require('../common.js'); | |
| 3 | - const PORT = common.PORT; | ||
| 4 | 3 | ||
| 5 | 4 | const bench = common.createBenchmark(main, { | |
| 6 | 5 | res: ['normal', 'setHeader', 'setHeaderWH'], | |
@@ -17,16 +16,16 @@ const c = 50; | |||
| 17 | 16 | // setHeader: statusCode = status, setHeader(...) x2 | |
| 18 | 17 | // setHeaderWH: setHeader(...), writeHead(status, ...) | |
| 19 | 18 | function main({ res, duration }) { | |
| 20 | - process.env.PORT = PORT; | ||
| 21 | 19 | const server = require('../fixtures/simple-http-server.js') | |
| 22 | - .listen(PORT) | ||
| 20 | + .listen(0) | ||
| 23 | 21 | .on('listening', () => { | |
| 24 | 22 | const path = `/${type}/${len}/${chunks}/${res}/${chunkedEnc}`; | |
| 25 | 23 | ||
| 26 | 24 | bench.http({ | |
| 27 | 25 | path: path, | |
| 28 | 26 | connections: c, | |
| 29 | - duration | ||
| 27 | + duration, | ||
| 28 | + port: server.address().port, | ||
| 30 | 29 | }, () => { | |
| 31 | 30 | server.close(); | |
| 32 | 31 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,14 +13,15 @@ const bench = common.createBenchmark(main, { | |||
| 13 | 13 | ||
| 14 | 14 | function main({ type, len, chunks, c, chunkedEnc, duration }) { | |
| 15 | 15 | const server = require('../fixtures/simple-http-server.js') | |
| 16 | - .listen(common.PORT) | ||
| 16 | + .listen(0) | ||
| 17 | 17 | .on('listening', () => { | |
| 18 | 18 | const path = `/${type}/${len}/${chunks}/normal/${chunkedEnc}`; | |
| 19 | 19 | ||
| 20 | 20 | bench.http({ | |
| 21 | 21 | path, | |
| 22 | 22 | connections: c, | |
| 23 | - duration | ||
| 23 | + duration, | ||
| 24 | + port: server.address().port, | ||
| 24 | 25 | }, () => { | |
| 25 | 26 | server.close(); | |
| 26 | 27 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,7 +20,7 @@ const resData = 'HTTP/1.1 101 Web Socket Protocol Handshake\r\n' + | |||
| 20 | 20 | ||
| 21 | 21 | function main({ n }) { | |
| 22 | 22 | const server = require('../fixtures/simple-http-server.js') | |
| 23 | - .listen(common.PORT) | ||
| 23 | + .listen(0) | ||
| 24 | 24 | .on('listening', () => { | |
| 25 | 25 | bench.start(); | |
| 26 | 26 | doBench(server.address(), n, () => { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1364,15 +1364,12 @@ added: | |||
| 1364 | 1364 | Limit the amount of time the parser will wait to receive the complete HTTP | |
| 1365 | 1365 | headers. | |
| 1366 | 1366 | ||
| 1367 | - In case of inactivity, the rules defined in [`server.timeout`][] apply. However, | ||
| 1368 | - that inactivity based timeout would still allow the connection to be kept open | ||
| 1369 | - if the headers are being sent very slowly (by default, up to a byte per 2 | ||
| 1370 | - minutes). In order to prevent this, whenever header data arrives an additional | ||
| 1371 | - check is made that more than `server.headersTimeout` milliseconds has not | ||
| 1372 | - passed since the connection was established. If the check fails, a `'timeout'` | ||
| 1373 | - event is emitted on the server object, and (by default) the socket is destroyed. | ||
| 1374 | - See [`server.timeout`][] for more information on how timeout behavior can be | ||
| 1375 | - customized. | ||
| 1367 | + If the timeout expires, the server responds with status 408 without | ||
| 1368 | + forwarding the request to the request listener and then closes the connection. | ||
| 1369 | + | ||
| 1370 | + It must be set to a non-zero value (e.g. 120 seconds) to protect against | ||
| 1371 | + potential Denial-of-Service attacks in case the server is deployed without a | ||
| 1372 | + reverse proxy in front. | ||
| 1376 | 1373 | ||
| 1377 | 1374 | ### `server.listen()` | |
| 1378 | 1375 | ||
@@ -1401,9 +1398,14 @@ Limits maximum incoming headers count. If set to 0, no limit will be applied. | |||
| 1401 | 1398 | ||
| 1402 | 1399 | <!-- YAML | |
| 1403 | 1400 | added: v14.11.0 | |
| 1401 | + changes: | ||
| 1402 | + - version: REPLACEME | ||
| 1403 | + pr-url: https://github.com/nodejs/node/pull/41263 | ||
| 1404 | + description: The default request timeout changed | ||
| 1405 | + from no timeout to 300s (5 minutes). | ||
| 1404 | 1406 | --> | |
| 1405 | 1407 | ||
| 1406 | - * {number} **Default:** `0` | ||
| 1408 | + * {number} **Default:** `300000` | ||
| 1407 | 1409 | ||
| 1408 | 1410 | Sets the timeout value in milliseconds for receiving the entire request from | |
| 1409 | 1411 | the client. | |
@@ -2856,6 +2858,10 @@ Found'`. | |||
| 2856 | 2858 | <!-- YAML | |
| 2857 | 2859 | added: v0.1.13 | |
| 2858 | 2860 | changes: | |
| 2861 | + - version: REPLACEME | ||
| 2862 | + pr-url: https://github.com/nodejs/node/pull/41263 | ||
| 2863 | + description: The `requestTimeout`, `headersTimeout`, `keepAliveTimeout` and | ||
| 2864 | + `connectionsCheckingInterval` are supported now. | ||
| 2859 | 2865 | - version: REPLACEME | |
| 2860 | 2866 | pr-url: https://github.com/nodejs/node/pull/42163 | |
| 2861 | 2867 | description: The `noDelay` option now defaults to `true`. | |
@@ -2886,6 +2892,22 @@ changes: | |||
| 2886 | 2892 | * `ServerResponse` {http.ServerResponse} Specifies the `ServerResponse` class | |
| 2887 | 2893 | to be used. Useful for extending the original `ServerResponse`. **Default:** | |
| 2888 | 2894 | `ServerResponse`. | |
| 2895 | + * `requestTimeout`: Sets the timeout value in milliseconds for receiving | ||
| 2896 | + the entire request from the client. | ||
| 2897 | + See [`server.requestTimeout`][] for more information. | ||
| 2898 | + **Default:** `300000`. | ||
| 2899 | + * `headersTimeout`: Sets the timeout value in milliseconds for receiving | ||
| 2900 | + the complete HTTP headers from the client. | ||
| 2901 | + See [`server.headersTimeout`][] for more information. | ||
| 2902 | + **Default:** `60000`. | ||
| 2903 | + * `keepAliveTimeout`: The number of milliseconds of inactivity a server | ||
| 2904 | + needs to wait for additional incoming data, after it has finished writing | ||
| 2905 | + the last response, before a socket will be destroyed. | ||
| 2906 | + See [`server.keepAliveTimeout`][] for more information. | ||
| 2907 | + **Default:** `5000`. | ||
| 2908 | + * `connectionsCheckingInterval`: Sets the interval value in milliseconds to | ||
| 2909 | + check for request and headers timeout in incomplete requests. | ||
| 2910 | + **Default:** `30000`. | ||
| 2889 | 2911 | * `insecureHTTPParser` {boolean} Use an insecure HTTP parser that accepts | |
| 2890 | 2912 | invalid HTTP headers when `true`. Using the insecure parser should be | |
| 2891 | 2913 | avoided. See [`--insecure-http-parser`][] for more information. | |
@@ -3478,7 +3500,10 @@ try { | |||
| 3478 | 3500 | [`response.write(data, encoding)`]: #responsewritechunk-encoding-callback | |
| 3479 | 3501 | [`response.writeContinue()`]: #responsewritecontinue | |
| 3480 | 3502 | [`response.writeHead()`]: #responsewriteheadstatuscode-statusmessage-headers | |
| 3503 | + [`server.headersTimeout`]: #serverheaderstimeout | ||
| 3504 | + [`server.keepAliveTimeout`]: #serverkeepalivetimeout | ||
| 3481 | 3505 | [`server.listen()`]: net.md#serverlisten | |
| 3506 | + [`server.requestTimeout`]: #serverrequesttimeout | ||
| 3482 | 3507 | [`server.timeout`]: #servertimeout | |
| 3483 | 3508 | [`setHeader(name, value)`]: #requestsetheadername-value | |
| 3484 | 3509 | [`socket.connect()`]: net.md#socketconnectoptions-connectlistener | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -735,8 +735,7 @@ function tickOnSocket(req, socket) { | |||
| 735 | 735 | parser.initialize(HTTPParser.RESPONSE, | |
| 736 | 736 | new HTTPClientAsyncResource('HTTPINCOMINGMESSAGE', req), | |
| 737 | 737 | req.maxHeaderSize || 0, | |
| 738 | - lenient ? kLenientAll : kLenientNone, | ||
| 739 | - 0); | ||
| 738 | + lenient ? kLenientAll : kLenientNone); | ||
| 740 | 739 | parser.socket = socket; | |
| 741 | 740 | parser.outgoing = req; | |
| 742 | 741 | req.parser = parser; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments