Skip to content

fix: don't clone request in prefix stripping#70

Open
mromaszewicz wants to merge 1 commit intooapi-codegen:mainfrom
mromaszewicz:fix/issue-69
Open

fix: don't clone request in prefix stripping#70
mromaszewicz wants to merge 1 commit intooapi-codegen:mainfrom
mromaszewicz:fix/issue-69

Conversation

@mromaszewicz
Copy link
Copy Markdown
Member

Closes: #69

Replace makeRequestForValidation (which used r.Clone()) with withPrefixStripped, which temporarily modifies the request's path fields in place and restores them after validation.

r.Clone() shallow-copies the Body, so when validation consumed the body on the clone, the original request passed to the handler had an empty body, causing 'EOF' errors on decode.

The new approach mutates the path fields for the duration of route finding and validation, then restores them before the handler or error handler sees the request. No clone, no body sharing, no buffering of potentially large request bodies.

The r.Clone() was only done as a way to back up the request URI to send the prefix-stripped request into validation.

Fixes #69

Closes: oapi-codegen#69

Replace makeRequestForValidation (which used r.Clone()) with
withPrefixStripped, which temporarily modifies the request's path
fields in place and restores them after validation.

r.Clone() shallow-copies the Body, so when validation consumed the
body on the clone, the original request passed to the handler had an
empty body, causing 'EOF' errors on decode.

The new approach mutates the path fields for the duration of route
finding and validation, then restores them before the handler or error
handler sees the request. No clone, no body sharing, no buffering of
potentially large request bodies.

The r.Clone() was only done as a way to back up the request URI to
send the prefix-stripped request into validation.

Fixes oapi-codegen#69

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mromaszewicz mromaszewicz requested a review from a team as a code owner April 3, 2026 17:38
@mromaszewicz mromaszewicz added the bug Something isn't working label Apr 3, 2026
@mromaszewicz mromaszewicz added this to the v1.2.0 milestone Apr 3, 2026
@GreyXor
Copy link
Copy Markdown
Contributor

GreyXor commented Apr 6, 2026

LGTM, I confirm that fix the issue #69
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prefix handling in validation introduced a regression with consuming the request body

2 participants