Skip to content

Refactor URLSessionHTTPClient out of HTTPClient#127

Open
guoye-zhang wants to merge 3 commits intoapple:mainfrom
guoye-zhang:urlsession-client
Open

Refactor URLSessionHTTPClient out of HTTPClient#127
guoye-zhang wants to merge 3 commits intoapple:mainfrom
guoye-zhang:urlsession-client

Conversation

@guoye-zhang
Copy link
Contributor

Several changes in this PR:

  1. Refactored URLSessionHTTPClient into its own target
  2. URLSessionHTTPClient, URLSessionRequestOptions, and URLSessionConnectionPoolConfiguration are now public types
  3. Renamed AsyncHTTPClientConformance into AHCHTTPClient since it sounds too similar to HTTPClientConformance which is a test suite
  4. DefaultHTTPClient is now backed by AHC on Linux

@guoye-zhang guoye-zhang added the ⚠️ semver/major Breaks existing public API. label Mar 7, 2026
@guoye-zhang
Copy link
Contributor Author

The Linux test failure appears to be a preexisting issue on main:

✘ Test conformance() recorded an issue at HTTPClientConformance.swift:97:33: Caught error: I/O on closed channel
↳ .test304WithContentLength

@fabianfett @xbhatnag

@xbhatnag
Copy link
Collaborator

xbhatnag commented Mar 9, 2026

The Linux test failure appears to be a preexisting issue on main:

✘ Test conformance() recorded an issue at HTTPClientConformance.swift:97:33: Caught error: I/O on closed channel
↳ .test304WithContentLength

@fabianfett @xbhatnag

Addressed in #128

xbhatnag added a commit that referenced this pull request Mar 11, 2026
### Motivation

The Raw Server handler would `return` every time it received a non-head
portion of the request. Unfortunately, every request has a `.end`
portion in addition to the `.head` portion, meaning that the server
would be tearing down the connection after one response despite not
including `Connection: close` in the headers, which confuses the client
trying to reuse the connection.

This caused AHC tests in Linux to flakily fail, as observed in #127 

### Modifications

To fix this, the raw server closes the connection correctly, by adding a
`Connection: close` header to all responses. The server now reads only
one set of request headers per connection, writes a response and then
closes that connection. Connection re-use is not permitted.

### Result

The AHC tests on Linux are not flaky anymore. Tested on docker container
running 204 + 304 tests back to back 100+ times.

### Test Plan

N/A. This fixes a test.

---------

Co-authored-by: Fabian Fett <fabianfett@apple.com>
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.

3 participants