Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce the ability to return 413: payload too large for requests #3040

Merged
merged 8 commits into from
Jan 2, 2023

Commits on Dec 25, 2022

  1. 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.
    shayonj committed Dec 25, 2022
    Configuration menu
    Copy the full SHA
    1034577 View commit details
    Browse the repository at this point in the history
  2. Compare and limit against body bytesize when no content-length

    http header is present.
    shayonj committed Dec 25, 2022
    Configuration menu
    Copy the full SHA
    2d9178b View commit details
    Browse the repository at this point in the history
  3. Update lib/puma/dsl.rb

    Co-authored-by: Nate Berkopec <nate.berkopec@gmail.com>
    shayonj and nateberkopec committed Dec 25, 2022
    Configuration menu
    Copy the full SHA
    fbb1a9d View commit details
    Browse the repository at this point in the history
  4. Update test

    shayonj committed Dec 25, 2022
    Configuration menu
    Copy the full SHA
    33d29d0 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    c1ab5c5 View commit details
    Browse the repository at this point in the history
  6. Add some more specs

    shayonj committed Dec 25, 2022
    Configuration menu
    Copy the full SHA
    248ca88 View commit details
    Browse the repository at this point in the history
  7. Removed unsued var

    shayonj committed Dec 25, 2022
    Configuration menu
    Copy the full SHA
    dc2b6ee View commit details
    Browse the repository at this point in the history

Commits on Dec 26, 2022

  1. Minor logic DRY up

    shayonj committed Dec 26, 2022
    Configuration menu
    Copy the full SHA
    dead2b4 View commit details
    Browse the repository at this point in the history