Skip to content

Switch HTTPClient response handler from a closure to a protocol#158

Open
guoye-zhang wants to merge 2 commits into
apple:mainfrom
guoye-zhang:response-handler
Open

Switch HTTPClient response handler from a closure to a protocol#158
guoye-zhang wants to merge 2 commits into
apple:mainfrom
guoye-zhang:response-handler

Conversation

@guoye-zhang
Copy link
Copy Markdown
Collaborator

Opening this to start a discussion. The new signature of perform:

    mutating func perform<ResponseHandler: HTTPClientResponseHandler & ~Copyable, Return: ~Copyable>(
        request: HTTPRequest,
        body: consuming HTTPClientRequestBody<RequestWriter>?,
        options: RequestOptions,
        responseHandler: consuming ResponseHandler
    ) async throws -> Return
    where
        ResponseHandler.ResponseConcludingReader: ~Copyable,
        ResponseHandler.ResponseConcludingReader == ResponseConcludingReader,
        ResponseHandler.Return == Return

Remaining:

  • Update docc comments
  • Decide what to do with convenience methods
  • Add support for informational responses in URLSession and AHC
  • Update proposal

@guoye-zhang guoye-zhang added the ⚠️ semver/major Breaks existing public API. label May 13, 2026
@_lifetime(&self)
#endif
mutating func perform<Return: ~Copyable>(
mutating func perform<ResponseHandler: HTTPClientResponseHandler & ~Copyable, Return: ~Copyable>(
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I was not able to get it to work with primary associated types due to SuppressedAssociatedTypesWithDefaults requiring ~Copyable for ResponseHandler.ResponseConcludingReader

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

Labels

⚠️ semver/major Breaks existing public API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant