Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions app/middleware/meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这逻辑有问题吧,在 14.12.0 之上的版本,都不应该 patch 了,交给 Node 本身来 patch

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我看错了,close


return async function meta(ctx, next) {
if (options.logging) {
Expand All @@ -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') {
/**
Expand Down