Is it possible to define custom max request size per endpoint?


I was wondering if it was possible to define a small request size for all the endpoint but set a higher for specific - “upload” - endpoint to allow for a higher value.

This would ensure that most of the endpoints don’t risk receiving a too heavy request while allowing a specific max size for dedicated endpoint.

I saw that an endpoint with stream=True can define a custom max request size, but I was wondering if this was possible for non-streamable endpoint.

Also, does it work to define a low REQUEST_MAX_SIZE for the whole project, and a higher for custom endpoint, or does the general configuration will trigger first?

Thank you for the help.

The general idea is that you should have a low setting for the whole project but then use streaming handlers for the few places where larger data is expected. A streaming handler can increase the value up to infinity and will not trigger on the general limit then.

Using non-streaming handlers with large requests makes your service vulnerable to denial of service attacks because someone can send many large requests to fill up all your RAM and crash your server. Thus, any large data should always use streaming and not buffer the whole thing in memory.

1 Like