-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce the ability to return 413: payload too large for requests (#…
…3040) * Introduce the ability to return 413: payload too large for requests When recieving large payload objects, the server can often slowdown or get fully exhausted if bunch of requests with large payload body size come in. When request with large payload come, lot of the time is spent reading it into then, writing it to the IO for rack, before the request is passed to the rails app for further processing. While there are some workarounds around limiting large request sizes, like at nginx layer by setting `client_max_body_size`, which would return a `413` back to the client, today that is not possible with puma. This would be a very nice feature to have, especially when there is no reverse proxy in between client and server. This approach - allows a user to set `http_content_length_limit_exceeded` via a config variable (defaults to `nil`). This value is then compared against `Content-Length` http header before reading the body into buffer. If the user value is higher than the header value, the request body is not loaded and an immediate `413` (`Payload too large`) http response is returned, from `Puma::Request.handle_request`. Without having to buffer in the huge request and return the `413` immediately to the clients that send a `Content-Length` - is a nice feature and helpful protection to have. * Compare and limit against body bytesize when no content-length http header is present. * Update lib/puma/dsl.rb Co-authored-by: Nate Berkopec <nate.berkopec@gmail.com> * Update test * Reset http_content_length_limit_exceeded * Add some more specs * Removed unsued var * Minor logic DRY up Co-authored-by: Nate Berkopec <nate.berkopec@gmail.com>
- Loading branch information
1 parent
8831577
commit 1c7804c
Showing
7 changed files
with
76 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters