http: improved timeout defaults handling · nodejs/node@7ea72ee · GitHub
Skip to content

Commit 7ea72ee

Browse files
ShogunPandalpinca
authored andcommitted
http: improved timeout defaults handling
Co-authored-by: Luigi Pinca <luigipinca@gmail.com> PR-URL: #45778 Fixes: #43355 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 4457e05 commit 7ea72ee

3 files changed

Lines changed: 59 additions & 4 deletions

File tree

doc/api/http.md

Lines changed: 5 additions & 1 deletion

lib/_http_server.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
const {
2525
ArrayIsArray,
2626
Error,
27+
MathMin,
2728
ObjectKeys,
2829
ObjectSetPrototypeOf,
2930
RegExpPrototypeExec,
@@ -446,11 +447,11 @@ function storeHTTPOptions(options) {
446447
validateInteger(headersTimeout, 'headersTimeout', 0);
447448
this.headersTimeout = headersTimeout;
448449
} else {
449-
this.headersTimeout = 60_000; // 60 seconds
450+
this.headersTimeout = MathMin(60_000, this.requestTimeout); // Minimum between 60 seconds or requestTimeout
450451
}
451452

452-
if (this.requestTimeout > 0 && this.headersTimeout > 0 && this.headersTimeout >= this.requestTimeout) {
453-
throw new codes.ERR_OUT_OF_RANGE('headersTimeout', '< requestTimeout', headersTimeout);
453+
if (this.requestTimeout > 0 && this.headersTimeout > 0 && this.headersTimeout > this.requestTimeout) {
454+
throw new codes.ERR_OUT_OF_RANGE('headersTimeout', '<= requestTimeout', headersTimeout);
454455
}
455456

456457
const keepAliveTimeout = options.keepAliveTimeout;
Lines changed: 50 additions & 0 deletions

0 commit comments

Comments
 (0)