Skip to content

Commit

Permalink
Allowing routes to specify the idle socket timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
kobelb committed Jul 17, 2020
1 parent 78b39e8 commit 9ce7c48
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/core/server/http/http_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export class HttpServer {
this.log.debug(`registering route handler for [${route.path}]`);
// Hapi does not allow payload validation to be specified for 'head' or 'get' requests
const validate = isSafeMethod(route.method) ? undefined : { payload: true };
const { authRequired, tags, body = {} } = route.options;
const { authRequired, tags, body = {}, timeout } = route.options;
const { accepts: allow, maxBytes, output, parse } = body;

const kibanaRouteState: KibanaRouteState = {
Expand All @@ -184,6 +184,9 @@ export class HttpServer {
payload: [allow, maxBytes, output, parse].some((v) => typeof v !== 'undefined')
? { allow, maxBytes, output, parse }
: undefined,
timeout: {
socket: timeout?.idleSocket,
},
},
});
}
Expand Down
10 changes: 10 additions & 0 deletions src/core/server/http/router/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@ export interface RouteConfigOptions<Method extends RouteMethod> {
* Additional body options {@link RouteConfigOptionsBody}.
*/
body?: Method extends 'get' | 'options' ? undefined : RouteConfigOptionsBody;

/**
* Defines per-route timeouts.
*/
timeout?: {
/**
* Milliseconds the socket can be idle before it's closed
*/
idleSocket?: number;
};
}

/**
Expand Down

0 comments on commit 9ce7c48

Please sign in to comment.