News KrakenD Enterprise v2.6 released with OpenTelemetry, FIPS-140, gRPC server and more

Enterprise Documentation

Recent changes

Limiting requests’ payload maximum size

Document updated on Apr 12, 2024

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
Maximum payload of Gzipped content
When you use 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"
* required fields
decompress_gzip

integer
Enterprise Only. Decompresses any Gzipped content before sending it to the backend when the Content-Encoding has gzip in the first position. You can also set this value per endpoint.
Defaults to 0
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 to 0

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
        }
    }
}
Fields of "proxy"
* required fields
decompress_gzip

boolean
Enterprise Only. Decompresses any Gzipped content before sending it to the backend when the Content-Encoding has gzip in the first position. You can also set this value globally at the service level.
Defaults to false
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 to 0
Scarf

Unresolved issues?

The documentation is only a piece of the help you can get! Whether you are looking for Open Source or Enterprise support, see more support channels that can help you.