Skip to content

Repo sync #32878

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
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
18 changes: 0 additions & 18 deletions src/frame/middleware/halt-on-dropped-connection.js

This file was deleted.

21 changes: 21 additions & 0 deletions src/frame/middleware/halt-on-dropped-connection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { NextFunction, Request, Response } from 'express'

// The `express-timeout-handler` middleware sets a property on
// the response object if it triggered a timeout.
// So we have to "pretend" that the request of this this type because
// it can be because of how that middleware works.
type ResponseWithGlobalTimeout = Response & { globalTimeout?: boolean }

export function isConnectionDropped(req: Request, res: ResponseWithGlobalTimeout) {
// Have the flags been set for:
// - a global request timeout (via the express-timeout-handler middleware)?
// - an aborted request connection (via Node.js core's HTTP IncomingMessage)?
return Boolean(res.globalTimeout || req.aborted)
}

export function haltOnDroppedConnection(req: Request, res: Response, next: NextFunction) {
// Only proceed if the flag has not been set for the express-timeout-handler middleware
if (!isConnectionDropped(req, res)) {
return next()
}
}
2 changes: 1 addition & 1 deletion src/frame/middleware/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import path from 'path'
import express from 'express'
import type { NextFunction, Request, Response, Express } from 'express'

import haltOnDroppedConnection from './halt-on-dropped-connection.js'
import { haltOnDroppedConnection } from './halt-on-dropped-connection'
import abort from './abort'
import timeout from './timeout.js'
import morgan from 'morgan'
Expand Down
2 changes: 1 addition & 1 deletion src/frame/middleware/render-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import getMiniTocItems from '#src/frame/lib/get-mini-toc-items.js'
import { pathLanguagePrefixed } from '#src/languages/lib/languages.js'
import statsd from '#src/observability/lib/statsd.js'
import { allVersions } from '#src/versions/lib/all-versions.js'
import { isConnectionDropped } from './halt-on-dropped-connection.js'
import { isConnectionDropped } from './halt-on-dropped-connection'
import { nextHandleRequest } from './next.js'
import { defaultCacheControl } from './cache-control.js'
import { minimumNotFoundHtml } from '../lib/constants.js'
Expand Down
Loading