Don't parse body when x-raw-body:true - #64
Merged
Merged
Conversation
x-raw-request currently passes the http.Request through to the handler as-is. This works well when there is no body defined in the openapi spec, which is how it has mostly been used to date. However when a body is defined in the openapi spec the body is parsed as per the spec. Beause r.Body() can only be read one time, this makes the raw request useless for any purposes that would access this body. This commit brings x-raw-request in line with the intended behaviour of leaving request processing to the handler by omitting the body parsing. This is a BREAKING CHANGE for any code that uses x-raw-request:true and a defined body, as the signature and responsibility of the user code changes.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #64 +/- ##
=======================================
Coverage ? 16.02%
=======================================
Files ? 42
Lines ? 3227
Branches ? 0
=======================================
Hits ? 517
Misses ? 2699
Partials ? 11 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Per https://lavajira.atlassian.net/browse/LP-520?focusedCommentId=55950 it was by design for x-raw-request to preserve body parsing. This request thus makes a separate x-raw-body extension that prevents body parsing. In order to allow x-raw-body without x-raw-request, the body io.ReadCloser is now passed in as a parameter.
leclark
reviewed
Aug 8, 2025
leclark
reviewed
Aug 8, 2025
leclark
approved these changes
Sep 29, 2025
bir
approved these changes
Oct 21, 2025
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.
Currently, if you define a body in openapi Foji will always parse it. This prevents handlers from doing different parsing than the spec, which is sometimes desired. This commit adds a x-raw-body extension to prevent parsing and instead pass r.Body directly through to the handler.