Repository navigation
Description
Problem
The lifecycle of the inbound request body is spread over Request and both engine loops as loose flags and conditionals (_hasBody, _bodyLoaded, _bodyStart, Upgrade() flipping _hasBody, and with #958 also _writer, _expectsContinue, ContinuePending, MarkResponseStarted() and a flush-before-drain in ClientHandler and Http1Driver). Every new body concern adds another bool and another if wherever it is needed.
Draining is a second symptom: it is a property of the framing, but it hangs off the consumption strategies. RequestBody.DrainAsync() creates a stream strategy just to drain, StreamConsumptionStrategy.DrainAsync() obtains and resets, and the memory strategy drains by replaying a stored ReadResult.
Proposal
The response side already solves this with sinks. The request side should get the same: one owner, a small surface.
1. RequestBody owns all inbound body state.
Reader, body start, framing, the chosen strategy, the body wrapper and (later) the continue expectation. Request keeps header concerns (e.g. retaining the header) and delegates GetBody(), Upgrade() and draining. No new owner type; RequestBody already exists and is pooled with the request.
2. Framing owns the position, not the strategies.
One small framing type per encoding (Content-Length, chunked) that holds remaining bytes or chunk parser state and offers a read and a skip. LengthLimitedStream, ChunkedBodyStream and the memory strategy become views over it. Draining becomes "skip the rest of the framing" - no strategy needs to be created to drain.
3. Two lifecycle calls for the engines.
ResponseStarting()- the final response is about to be written. Ideally called once from shared serialization code instead of in each engine.ValueTask<bool> FinishAsync()- finishes the body and returns whether the connection can be kept alive. Replaces the flush /DrainAsync()/ reset sequence inClientHandlerandHttp1Driver, so the loop becomes "if finish says close, close".
Effect on #958
On top of this, Expect: 100-continue reduces to:
- the framing's first read writes and flushes the 100 if armed (async, so the sync
GetBody()/AsStream()problem disappears), ResponseStarting()disarms it (no interim response after a final one, also for bodies read during response serialization),FinishAsync()decides between flush + skip and closing when the 100 was never sent,- the 417 stays in the compliance concern.
No ContinueReader, no new flags in Request or the engines. Since draining skips the framing directly, it never sends a 100 by construction.
Scope
- Refactor first, Answer Expect: 100-continue on HTTP/1.1 #958 rebased on top.
IRequestBodyandAsStream()/AsMemoryAsync()stay unchanged for users.- Existing acceptance tests should cover the refactor; Answer Expect: 100-continue on HTTP/1.1 #958's
ExpectContinueTestsfollow with it.
Activity
[-]Encapsulate the request body lifecycle in RequestBody (prerequisite for #958)[/-][+]Encapsulate the request body lifecycle in RequestBody[/+]