From 88f202ca97426e012ff88bd4eb9b344019b11474 Mon Sep 17 00:00:00 2001 From: rickyes <0x19951125@gmail.com> Date: Fri, 27 Nov 2020 15:47:45 +0800 Subject: [PATCH] fix: skip between Node.js 14.8.0 and 14.12.0 or equal to 12.19.0 to set Keep-Alive Header --- app/middleware/meta.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/middleware/meta.js b/app/middleware/meta.js index 680d115ffc..907c7a8733 100644 --- a/app/middleware/meta.js +++ b/app/middleware/meta.js @@ -7,8 +7,10 @@ const semver = require('semver'); module.exports = options => { - // Node.js >=14.8.0 and >= 12.19.0 will set Keep-Alive Header, see https://github.com/nodejs/node/pull/34561 - const shouldPatchKeepAliveHeader = !semver.satisfies(process.version, '>=14.8.0 || ^12.19.0'); + // Node.js >= 14.8.0 && < 14.12.0 and = 12.19.0 will set Keep-Alive Header + // Refs: https://github.com/nodejs/node/pull/34561 https://github.com/nodejs/node/pull/35138 + + const shouldPatchKeepAliveHeader = !semver.satisfies(process.version, '>=14.8.0 <14.12.0 || =12.19.0'); return async function meta(ctx, next) { if (options.logging) { @@ -18,7 +20,6 @@ module.exports = options => { // total response time header ctx.set('x-readtime', Date.now() - ctx.starttime); - // try to support Keep-Alive Header when < 14.8.0 const server = ctx.app.server; if (shouldPatchKeepAliveHeader && server && server.keepAliveTimeout && server.keepAliveTimeout >= 1000 && ctx.header.connection !== 'close') { /**