Repository navigation
Add continue_callback to answer Expect: 100-continue before the body is read - #4028
Merged
Merged
Conversation
…is read Puma replied 100 Continue to every request that asked for it, so an app had no way to turn a request away before the client sent the body. Redirecting an upload elsewhere, or refusing one that is too large, meant receiving the whole body first. The TODO in Client#setup_body has pointed at this since the header was first supported. continue_callback receives the Rack env, which has the headers but no body yet. Returning false or nil keeps today's behaviour. Returning a Rack response sends that instead: 100 Continue is not sent, the body is never read, the app is not called, and the connection is closed, since the client may already have started a body Puma will not read. The rejection travels as ContinueRejected through the existing client_error path, the same way the 413 for http_content_length_limit does, so it is answered from both the reactor and the thread pool. Without the option nothing changes. Closes puma#3188
IslamElsayed
marked this pull request as ready for review
September 27, 2026 12:51
Contributor
Author
|
Note on the red jobs: the four JRuby failures ( |
4 of 7 tasks
joshuay03
requested changes
Oct 2, 2026
Rack requires the server to close a response body that responds to #close; the callback's response was written but never closed. Also shorten the DSL doc to the callback's contract and one example.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Closes #3188.
Puma replies
100 Continueto every request that sendsExpect: 100-continue, so an app can't turn a request away before the client uploads the body — redirecting an upload elsewhere or refusing an oversized one means receiving it all first.Client#setup_bodyhas carried# TODO allow a hook here to check the headers before going forwardfor this.This implements the shape @nateberkopec proposed and @dentarg agreed in the issue, with
falseas the no-op per @dentarg's suggestion:false/nil— unchanged behaviour:100 Continueis sent and the request reaches the app.100 Continueis not sent, the body is never read, the app is not called, and the connection is closed.Without the option, nothing changes.
Decisions worth checking
http_content_length_limitalready refuses a request before reading its body, by raising fromsetup_bodyand lettingclient_errorwrite the response. This does the same with a newContinueRejectedthat carries the callback's response, so it's answered correctly whethersetup_bodyran on the reactor or in the thread pool — both already rescue intoclient_errorand then close the client. That's also why it adds no logging: answering early is the callback working, not an error.This supersedes #3200, which was closed as stale in November 2024.
Your checklist for this pull request
#issue" to the PR description or my commit messages.test_puma_server.rb(160 runs),test_config.rb(111),test_request_invalid_multiple.rb,test_http11.rband the hijack tests, all green, and Rubocop clean on the changed files. Each part of the change was also broken on purpose to confirm a test fails without it.Disclosure: I use AI assistance when working on patches, and I check and test everything before submitting.