Supports streaming response validation via streaming_content_parsers option - #447
Merged
Conversation
…` option Signed-off-by: moznion <moznion@mail.moznion.net>
geemus
reviewed
Jul 6, 2025
geemus
reviewed
Jul 6, 2025
geemus
reviewed
Jul 6, 2025
geemus
left a comment
Member
There was a problem hiding this comment.
Looking good overall, added a couple questions to discuss, and I think this looks pretty close already. Thanks!
…tion” section. Signed-off-by: moznion <moznion@mail.moznion.net>
geemus
approved these changes
Aug 2, 2025
geemus
left a comment
Member
There was a problem hiding this comment.
LGTM, sorry it took me so long to get back to it, July ended up being surprisingly hectic.
Member
|
@moznion did you need a release with this? |
Contributor
Author
|
@geemus |
Member
|
@moznion This has been released as part of v5.5.5. Thanks! |
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.
Background
In the existing implementation, when the response body of streaming events such as Server-Sent Events passes through
Committee::Middleware::ResponseValidation, theresponse_validatemethod from OpenAPI 3 (or HyperSchema) blocks until the entire body is read. As a result, it was not possible to return responses as streams.As a workaround for this issue, the one of the solutions is to use a middleware wrapper like the below to completely skip validation for the corresponding endpoint.
Features Added by This Patch
This patch adds an option called
streaming_content_parserstoCommittee::Middleware::ResponseValidation. This option accepts a hash where the key is a Content-Type and the value is a Proc that receives and transforms the response body of that Content-Type.Content-Types specified via this option bypass the normal path (which waits for the entire body to be read) and instead go through a path via
Rack::BodyProxy. This allows the response to be streamed to the client without blocking, while still enabling validation to be performed on the transformed body via the Proc once the response body is closed.Usage Example
Limitations
For limitations of this feature, please refer to the README.