Skip to content

Refactor HTTP client#764

Open
stevenzeck wants to merge 17 commits intoreadium:swift6from
stevenzeck:refactor-httpclient
Open

Refactor HTTP client#764
stevenzeck wants to merge 17 commits intoreadium:swift6from
stevenzeck:refactor-httpclient

Conversation

@stevenzeck
Copy link
Copy Markdown
Contributor

@stevenzeck stevenzeck commented Apr 1, 2026

Key Change: HTTP Client Refactor

  1. Introduced HTTPFetchResponse to clearly separate response metadata (HTTPResponse) from the full response body (Data).
  2. Refactored HTTPClient.stream to include an onReceiveResponse async callback, allowing for early interception of headers and potential request cancellation.
  3. Improved HTTPResponse with more robust filename extraction from Content-Disposition headers and better support for byte-range requests (added fullContentLength and contentRangeOffset).
  4. Updated DefaultHTTPClient with a cleaner implementation using URLSessionDataDelegate.
  5. Significant increase in test coverage for the HTTP layer (HTTPClient, HTTPRequest, HTTPResponse, HTTPResource).

Public API Breaking Changes

  1. HTTPClient protocol: stream(request:onReceiveResponse:consume:) now requires the onReceiveResponse parameter.
  2. HTTPClient extensions: fetch(_:) now returns HTTPResult<HTTPFetchResponse> instead of HTTPResult<HTTPResponse>.
  3. HTTPResponse struct: The body: Data? property has been removed. Body data is now accessed via HTTPFetchResponse.body after a fetch call.
  4. HTTPStatus struct: The isSuccess property now returns true only for 2xx status codes (200-299). It previously included 3xx codes (200-399).
  5. HTTPError enum: The .errorResponse case now takes an HTTPFetchResponse instead of an HTTPResponse.

@stevenzeck stevenzeck changed the base branch from develop to swift6 April 1, 2026 15:40
@stevenzeck stevenzeck marked this pull request as ready for review April 2, 2026 01:06
@mickael-menu mickael-menu force-pushed the swift6 branch 2 times, most recently from 7f68304 to 47fda4b Compare April 2, 2026 10:34
@stevenzeck stevenzeck marked this pull request as ready for review April 2, 2026 16:56
@stevenzeck
Copy link
Copy Markdown
Contributor Author

@mickael-menu any other items you think would be worth addressing here?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant