Document updated on Nov 12, 2024
Limiting requests’ payload maximum size
Consumers of the gateway might see their requests limited when using the max_payload
property. All requests are validated when this attribute is set, checking that their size is inside the limits set.
There are two possible placements of this attribute:
- At the service level: limits the requests of all activity
- At the endpoint level: limits the requests of specific endpoints
You can set both limits simultaneously if you want. When both limits exist, the service level limit is checked first, and if it passes, then it checks the endpoint limit. This means that the endpoint max_payload
must be equal to or smaller than the one at the service. Otherwise, the endpoint limit will never have an opportunity to work.
When users exceed the maximum number of bytes, they get the following status code:
HTTP/1.1 413 Request Entity Too Large
max_payload
in combination with decompress_gzip
when Gzip content goes through KrakenD, it is decompressed in the first place and the maximum payload applies to the decompressed payload.Limit the request size of all calls
When you want to limit the maximum request size of any request, add the following configuration at the service level under the router
property:
{
"version": 3,
"extra_config": {
"router": {
"max_payload": 1024
}
}
}
The configuration above limits all requests to 1KB (1024 bytes)
Fields of "router"
decompress_gzip
integer- Enterprise Only. Decompresses any Gzipped content before sending it to the backend when the
Content-Encoding
hasgzip
in the first position. You can also set this value per endpoint.Defaults to0
max_payload
integer- Enterprise Only. Limits the maximum number of bytes a user can send to the gateway.
0
means no limit. You can also set this value per endpoint.Defaults to0
Limit the maximum request size to an endpoint
When you want to limit the maximum payload you can send to an endpoint, place the flag under the proxy
entry of the endpoint. Remember that if you have also set the limit in the router
, that limit will kick in first. This is what you need to add to limit an endpoint:
{
"endpoint": "/body_size",
"method":"POST",
"backend": [
{
"url_pattern": "/__debug/body_size"
}
],
"extra_config":{
"proxy":{
"max_payload": 1024
}
}
}
Maximum payload configuration for proxy's extra_config
decompress_gzip
boolean- Enterprise Only. Decompresses any Gzipped content before sending it to the backend when the
Content-Encoding
hasgzip
in the first position. You can also set this value globally at the service level.Defaults tofalse
max_payload
integer- Enterprise Only. Limits the maximum number of bytes a user can send to the endpoint.
0
means no limit. You can also set this value globally at the service level.Defaults to0