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

[8.13] Add `http.payloadTimeout` config option (#177309) #177574

Merged
merged 1 commit into from
Feb 22, 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
5 changes: 5 additions & 0 deletions docs/setup/settings.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,11 @@ default is `true`. *Default: `deprecated`*
The number of milliseconds to wait before closing an
inactive socket. *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-ssl-cert-key]] `server.ssl.certificate` and `server.ssl.key`::
Paths to a PEM-encoded X.509 server certificate and its corresponding private key. These
are used by {kib} to establish trust when receiving inbound SSL/TLS connections from users.
Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,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 packages/core/http/core-http-server-internal/src/http_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import {
} from './security_response_headers_config';
import { CdnConfig } from './cdn_config';

const SECOND = 1000;

const validBasePathRegex = /^\/.*[^\/]$/;

const hostURISchema = schema.uri({ scheme: ['http', 'https'] });
Expand Down Expand Up @@ -129,10 +131,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 @@ -278,6 +283,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 @@ -342,6 +348,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
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 @@ -53,6 +56,7 @@ export class HttpConfig implements IHttpConfig {
shutdownTimeout: Duration;
keepaliveTimeout: number;
socketTimeout: number;
payloadTimeout: number;
cors: ICorsConfig;
ssl: ISslConfig;
restrictInternalApis: boolean;
Expand All @@ -64,6 +68,7 @@ export class HttpConfig implements IHttpConfig {
this.maxPayload = rawConfig.maxPayload;
this.shutdownTimeout = rawConfig.shutdownTimeout;
this.keepaliveTimeout = rawConfig.keepaliveTimeout;
this.payloadTimeout = rawConfig.payloadTimeout;
this.socketTimeout = rawConfig.socketTimeout;
this.cors = rawConfig.cors;
this.ssl = new SslConfig(rawConfig.ssl);
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe('server config', () => {
"maxPayload": ByteSizeValue {
"valueInBytes": 1048576,
},
"payloadTimeout": 20000,
"port": 3000,
"restrictInternalApis": false,
"shutdownTimeout": "PT30S",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ const configSchema = schema.object(
keepaliveTimeout: schema.number({
defaultValue: 120000,
}),
payloadTimeout: schema.number({
defaultValue: 20000,
}),
shutdownTimeout: schema.duration({
defaultValue: '30s',
validate: (duration) => {
Expand Down Expand Up @@ -73,6 +76,7 @@ export class ServerConfig implements IHttpConfig {
keepaliveTimeout: number;
shutdownTimeout: Duration;
socketTimeout: number;
payloadTimeout: number;
ssl: ISslConfig;
cors: ICorsConfig;
restrictInternalApis: boolean;
Expand All @@ -84,6 +88,7 @@ export class ServerConfig implements IHttpConfig {
this.keepaliveTimeout = rawConfig.keepaliveTimeout;
this.shutdownTimeout = rawConfig.shutdownTimeout;
this.socketTimeout = rawConfig.socketTimeout;
this.payloadTimeout = rawConfig.payloadTimeout;
this.ssl = new SslConfig(rawConfig.ssl);
this.cors = {
enabled: false,
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 @@ -122,4 +123,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
Loading