GH-516 parity for HTTP: Before middleware can replace an immutable request body - #3984
Open
danniewalden wants to merge 1 commit into
Open
GH-516 parity for HTTP: Before middleware can replace an immutable request body#3984danniewalden wants to merge 1 commit into
danniewalden wants to merge 1 commit into
Conversation
…fore middleware replace the request (JasperFxGH-516 parity) Message handler chains have supported middleware replacing an immutable message since JasperFxGH-516: a Before/BeforeAsync method that accepts the message type and returns it (optionally in a tuple) overwrites the original for the rest of the chain. HTTP chains never got the same codegen pass, so the same pattern on an endpoint class generated a colliding local variable and failed compilation (CS0841/CS0136). This mirrors the HandlerChain.DetermineFrames pass onto HttpChain.DetermineFrames, with two HTTP-specific guards: skip when the chain has no request body, and skip the frame that reads the request body itself (the Newtonsoft reader is a MethodCall whose ReturnVariable IS the request body variable). Scope is deliberately limited to Before methods declared on the endpoint class; externally registered middleware returning the request type is still guarded by the existing MiddlewarePolicy exception. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
danniewalden
force-pushed
the
http-middleware-message-replacement
branch
from
August 20, 2026 08:55
7dcf5a7 to
ca1e05f
Compare
danniewalden
marked this pull request as ready for review
August 20, 2026 09:06
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.
Motivation
Handler chains have supported middleware replacing an immutable message since GH-516: a
Before/BeforeAsyncaccepting the message type and returning it (optionally in a tuple) overwrites the message for the rest of the chain. HTTP chains lack the equivalent pass, so the same pattern on an endpoint class fails compilation with a colliding local (CS0841/CS0136):Changes
Mirrors the
HandlerChain.DetermineFramesGH-516 pass ontoHttpChain.DetermineFrames(12 lines), with two HTTP-specific guards:MethodCallwhoseReturnVariableis the request body variable; flipping it would delete the declarationSync, async, and tuple-returning
Beforemethods behave identically to the handler side.Out of scope
Registered middleware (
Policies.AddMiddleware,[Middleware]) returning the request type is still blocked by the existingMiddlewarePolicyexception.Tests
middleware_replacing_immutable_request: Bug_516-style chained sync/async/tuple fact + tupleIResultshort-circuitusing_newtonsoft_for_serialization: regression for the body-reader skipdocs/guide/http/middleware.mdFull net9.0-pinned
wolverine.slnxbuild clean;Wolverine.Http.TestsandCoreTestssuites green.🤖 Generated with Claude Code