Skip to content

Commit

Permalink
Backport #177309 to 7.17
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed May 7, 2024
1 parent 0dadb78 commit d8f10e8
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 2 deletions.
5 changes: 5 additions & 0 deletions docs/setup/settings.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,11 @@ back end server. To allow remote users to connect, set the value to the IP addre
The number of milliseconds to wait for additional data before restarting
the <<server-socketTimeout, `server.socketTimeout`>> counter. *Default: `"120000"`*

[[server-payloadTimeout]] `server.payloadTimeout`::
Sets the maximum time allowed for the client to transmit the request payload (body) before giving up
and responding with a Request Timeout (408) error response.
*Default: `"20000"`*

[[server-maxPayload]] `server.maxPayload`::
The maximum payload size in bytes
for incoming server requests. *Default: `1048576`*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ describe('BasePathProxyServer', () => {
shutdownTimeout: moment.duration(30, 'seconds'),
keepaliveTimeout: 1000,
socketTimeout: 1000,
payloadTimeout: 1000,
cors: {
enabled: false,
allowCredentials: false,
Expand Down
5 changes: 5 additions & 0 deletions packages/kbn-cli-dev-mode/src/config/http_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export const httpConfigSchema = schema.object(
socketTimeout: schema.number({
defaultValue: 120000,
}),
payloadTimeout: schema.number({
defaultValue: 20000,
}),
cors: schema.object({
enabled: schema.boolean({ defaultValue: false }),
allowCredentials: schema.boolean({ defaultValue: false }),
Expand All @@ -52,6 +55,7 @@ export class HttpConfig implements IHttpConfig {
shutdownTimeout: Duration;
keepaliveTimeout: number;
socketTimeout: number;
payloadTimeout: number;
cors: ICorsConfig;
ssl: ISslConfig;

Expand All @@ -63,6 +67,7 @@ export class HttpConfig implements IHttpConfig {
this.shutdownTimeout = rawConfig.shutdownTimeout;
this.keepaliveTimeout = rawConfig.keepaliveTimeout;
this.socketTimeout = rawConfig.socketTimeout;
this.payloadTimeout = rawConfig.payloadTimeout;
this.cors = rawConfig.cors;
this.ssl = new SslConfig(rawConfig.ssl);
}
Expand Down
9 changes: 9 additions & 0 deletions packages/kbn-server-http-tools/src/get_server_options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const createConfig = (parts: Partial<IHttpConfig>): IHttpConfig => ({
port: 5601,
socketTimeout: 120000,
keepaliveTimeout: 120000,
payloadTimeout: 20000,
shutdownTimeout: moment.duration(30, 'seconds'),
maxPayload: ByteSizeValue.parse('1048576b'),
...parts,
Expand Down Expand Up @@ -121,4 +122,12 @@ describe('getServerOptions', () => {
headers: ['Accept', 'Authorization', 'Content-Type', 'If-None-Match', 'kbn-xsrf'],
});
});

it('properly configures `routes.payload.timeout`', () => {
const httpConfig = createConfig({
payloadTimeout: 9007,
});

expect(getServerOptions(httpConfig).routes!.payload!.timeout).toEqual(9007);
});
});
1 change: 1 addition & 0 deletions packages/kbn-server-http-tools/src/get_server_options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export function getServerOptions(config: IHttpConfig, { configureTLS = true } =
cors,
payload: {
maxBytes: config.maxPayload.getValueInBytes(),
timeout: config.payloadTimeout,
},
validate: {
failAction: defaultValidationErrorHandler,
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-server-http-tools/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface IHttpConfig {
maxPayload: ByteSizeValue;
keepaliveTimeout: number;
socketTimeout: number;
payloadTimeout: number;
cors: ICorsConfig;
ssl: ISslConfig;
shutdownTimeout: Duration;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/core/server/http/http_config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,14 @@ test('can specify socket timeouts', () => {
expect(socketTimeout).toBe(5e5);
});

test('can specify payload timeouts', () => {
const obj = {
payloadTimeout: 654321,
};
const { payloadTimeout } = config.schema.validate(obj);
expect(payloadTimeout).toBe(654321);
});

describe('with compression', () => {
test('accepts valid referrer whitelist', () => {
const {
Expand Down
11 changes: 9 additions & 2 deletions src/core/server/http/http_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import {
parseRawSecurityResponseHeadersConfig,
} from './security_response_headers_config';

const SECOND = 1000;

const validBasePathRegex = /^\/.*[^\/]$/;
export const uuidRegexp =
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
Expand Down Expand Up @@ -97,10 +99,13 @@ const configSchema = schema.object(
rewriteBasePath: schema.boolean({ defaultValue: false }),
ssl: sslSchema,
keepaliveTimeout: schema.number({
defaultValue: 120000,
defaultValue: 120 * SECOND,
}),
socketTimeout: schema.number({
defaultValue: 120000,
defaultValue: 120 * SECOND,
}),
payloadTimeout: schema.number({
defaultValue: 20 * SECOND,
}),
compression: schema.object({
enabled: schema.boolean({ defaultValue: true }),
Expand Down Expand Up @@ -188,6 +193,7 @@ export class HttpConfig implements IHttpConfig {
public host: string;
public keepaliveTimeout: number;
public socketTimeout: number;
public payloadTimeout: number;
public port: number;
public cors: {
enabled: boolean;
Expand Down Expand Up @@ -245,6 +251,7 @@ export class HttpConfig implements IHttpConfig {
this.publicBaseUrl = rawHttpConfig.publicBaseUrl;
this.keepaliveTimeout = rawHttpConfig.keepaliveTimeout;
this.socketTimeout = rawHttpConfig.socketTimeout;
this.payloadTimeout = rawHttpConfig.payloadTimeout;
this.rewriteBasePath = rawHttpConfig.rewriteBasePath;
this.ssl = new SslConfig(rawHttpConfig.ssl || {});
this.compression = rawHttpConfig.compression;
Expand Down

0 comments on commit d8f10e8

Please sign in to comment.