Skip to content

Fix streaming failing with "range not supported" on servers negotiating compression - #864

Draft
mickael-menu wants to merge 1 commit into
developfrom
fix-issue-653
Draft

Fix streaming failing with "range not supported" on servers negotiating compression#864
mickael-menu wants to merge 1 commit into
developfrom
fix-issue-653

Conversation

@mickael-menu

Copy link
Copy Markdown
Member

Fixes #653.

URLSession transparently negotiates compressed responses (gzip/deflate/br), but servers usually cannot serve byte ranges of a compressed representation and omit Accept-Ranges in that case. DefaultHTTPClient then misinterpreted the 200 response as the server not supporting byte ranges and failed with HTTPError.rangeNotSupported, breaking streamed publications (e.g. from the Readium publication server).

DefaultHTTPClient now sends Accept-Encoding: identity with any byte range request that doesn't already specify an Accept-Encoding, ensuring the server advertises and serves ranges properly. Callers can still override the header explicitly.

🤖 Generated with Claude Code

…ompression

Fixes #653.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@mickael-menu
mickael-menu changed the base branch from swift6 to develop August 5, 2026 14:27
// Requesting the identity encoding ensures the server advertises and
// serves byte ranges properly.
// See https://github.com/readium/swift-toolkit/issues/653
if request.hasHeader("Range"), !request.hasHeader("Accept-Encoding") {

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.

Nothing wrong, might be better if this was in HTTPRequest as a mutating function.

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.

2 participants