File tree Expand file tree Collapse file tree 2 files changed +8
-2
lines changed
Expand file tree Collapse file tree 2 files changed +8
-2
lines changed Original file line number Diff line number Diff line change 44
55'use strict' ;
66
7+ const semver = require ( 'semver' ) ;
8+
79module . exports = options => {
810 return async function meta ( ctx , next ) {
911 if ( options . logging ) {
@@ -13,9 +15,12 @@ module.exports = options => {
1315 // total response time header
1416 ctx . set ( 'x-readtime' , Date . now ( ) - ctx . starttime ) ;
1517
16- // try to support Keep-Alive Header
18+ // Node.js >=14.8.0 will set Keep-Alive Header, see https://github.com/nodejs/node/pull/34561
19+ const shouldPatchKeepAliveHeader = semver . lt ( process . version , '14.8.0' ) ;
20+
21+ // try to support Keep-Alive Header when < 14.8.0
1722 const server = ctx . app . server ;
18- if ( server && server . keepAliveTimeout && server . keepAliveTimeout >= 1000 && ctx . header . connection !== 'close' ) {
23+ if ( shouldPatchKeepAliveHeader && server && server . keepAliveTimeout && server . keepAliveTimeout >= 1000 && ctx . header . connection !== 'close' ) {
1924 /**
2025 * use Math.floor instead of parseInt. More: https://github.com/eggjs/egg/pull/2702
2126 */
Original file line number Diff line number Diff line change 4949 "ms" : " ^2.1.1" ,
5050 "mz" : " ^2.7.0" ,
5151 "on-finished" : " ^2.3.0" ,
52+ "semver" : " ^7.3.2" ,
5253 "sendmessage" : " ^1.1.0" ,
5354 "urllib" : " ^2.33.0" ,
5455 "utility" : " ^1.15.0" ,
You can’t perform that action at this time.
0 commit comments