Skip to content
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

Configure node HTTP server timeouts #98

Open
wants to merge 1 commit into
base: 7.x
Choose a base branch
from
Open
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
25 changes: 25 additions & 0 deletions src/server/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,31 @@ export class Server {
* Set the HTTP server instance used to listen for requests.
*/
setNodeServer(server: HttpServer | HttpsServer) {
if (this.#config.nodeHttpServer) {
const {
keepAliveTimeout,
headersTimeout,
requestTimeout,
timeout,
} = this.#config.nodeHttpServer

if (typeof keepAliveTimeout === 'number') {
server.keepAliveTimeout = keepAliveTimeout
}

if (typeof headersTimeout === 'number') {
server.headersTimeout = headersTimeout
}

if (typeof requestTimeout === 'number') {
server.requestTimeout = requestTimeout
}

if (typeof timeout === 'number') {
server.timeout = timeout
}
}

this.#nodeHttpServer = server
}

Expand Down
30 changes: 30 additions & 0 deletions src/types/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,34 @@ export type ServerConfig = RequestConfig &
* Config for query string parser
*/
qs: QSParserConfig

/**
* Node.js HTTP server options
*/
nodeHttpServer?: {
/**
* The number of milliseconds of inactivity a server needs to wait for additional incoming data, after
* it has finished writing the last response, before a socket will be destroyed
* @default 5000
*/
keepAliveTimeout?: number

/**
* Limit the amount of time the parser will wait to receive the complete HTTP headers
* @default 60000
*/
headersTimeout?: number

/**
* Sets the timeout value in milliseconds for receiving the entire request from the client
* @default 300000
*/
requestTimeout?: number

/**
* The number of milliseconds of inactivity before a socket is presumed to have timed out
* @default 0
*/
timeout?: number
}
}