Skip to content

Correctly handle inputClosed event - #13

Merged
aryan-25 merged 13 commits into
apple:mainfrom
aryan-25:handle-input-closed
Aug 11, 2026
Merged

Correctly handle inputClosed event#13
aryan-25 merged 13 commits into
apple:mainfrom
aryan-25:handle-input-closed

Conversation

@aryan-25

@aryan-25 aryan-25 commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

Motivation

In HTTP3ToHTTPServerCodec and HTTP3ToHTTPClientCodec, we currently emit a response/request end part if the client/server terminated the stream with an incomplete response/request. This means that downstream handlers can receive a response/request end part before receiving a head/body part.

Per RFC 9114 §4.1, servers should abort the response stream with the H3_INCOMPLETE_REQUEST error code when a client-initiated stream is terminated before receiving enough request parts to provide a full response. Additionally, §4.1.1 describes that clients should not use partial responses.

Modifications

  • When we receive the .inputClosed event, HTTP3FrameValidator now checks whether it received a complete request/response, and returns one of three actions: .doNothing (if we received a complete request/response), .notifyDownstream (if we received an incomplete response (clients only)), or .resetStream (if we received an incomplete request (servers only)).
  • HTTP3StreamStateMachine now passes that action as an associated value on the inputClosed action.
  • HTTP3StreamHandler fires the inputClosed event as before, but for an incomplete message it first fires an HTTP3Error down the pipeline, and for servers, it also sends a QUICResetStreamEvent with the H3_REQUEST_INCOMPLETE code.
  • HTTPMessageParsingStateMachine no longer emits an end part when the input closes before a head part arrives.
  • Added a peerTerminatedInboundStream case to HTTP3Error.Code.

Result

HTTP3ToHTTPServerCodec and HTTP3ToHTTPClientCodec no longer emit a request/response end part if the stream has terminated without a complete request/response.

Instead, HTTP3StreamHandler handler notifies downstream handlers with an error, and for servers, the stream is also reset.

@aryan-25 aryan-25 added the 🆕 semver/minor Adds new public API. label Jul 15, 2026
Comment thread Sources/HTTP3/HTTP3FrameValidator.swift
return false

case .headersProcessed:
// TODO: If a Content-Length header was specified, we need to check whether we have received all the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the TODO tracked somewhere / planned as a follow up?

@aryan-25
aryan-25 merged commit 5468df9 into apple:main Aug 11, 2026
30 checks passed
@aryan-25
aryan-25 deleted the handle-input-closed branch August 11, 2026 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🆕 semver/minor Adds new public API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants