我正在创建 RESTEasy 端点,我的请求应该是非常小的 JSON 格式,例如
{"id":"A1S2D3F4G5H6J7"}
RESTEasy中有没有办法限制客户端发送的信息量?我想阻止客户端发送 1GB 数据并中断我的服务。有什么想法吗?
最佳答案
这最好由网络服务器或应用程序服务器处理,而不是直接由应用程序代码处理。例如,假设您的应用程序服务器位于 Apache 后面。 Apache 通过 AJP 将请求代理到应用程序服务器。然后您可以设置 Apache 的 LimitRequestBody将配置属性设置为小于 1GB 的合理值,并防止这些大请求到达您的应用程序。
来自 Apache 文档:
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.
我假设所有其他主要 Web 服务器和应用程序容器都有处理这种情况的配置设置。
关于java - 创建 RESTEasy 端点时如何限制大型正文请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20207786/