Search code examples
javaresteasylarge-data

How to restrict large body requests when creating RESTEasy endpoints?


I'm creating RESTEasy endpoints and my requests are supposed to be JSON format of very small size like

    {"id":"A1S2D3F4G5H6J7"}

Is there a way in RESTEasy to restrict the amount of information sent by the client? I want to block a client from sending 1GB of data and bringing down my service. Any ideas?


Solution

  • This would be better handled by a web server or app server and not directly by your application code. For example, say you have your application server sitting behind Apache. Apache is proxying requests to the application server via AJP. You can then set Apache's LimitRequestBody configuration property to some sane value less than 1GB and prevent those large requests from coming through to your app.

    From the Apache Docs:

    The LimitRequestBody directive allows the user to set a limit on the allowed size of an HTTP request message body within the context in which the directive is given (server, per-directory, per-file or per-location). If the client request exceeds that limit, the server will return an error response instead of servicing the request.

    I would assume there are configuration settings for all of the other major web servers and application containers that handle this situation.