Skip to content

fix(http): download from servers that ignore ranges or fail HEAD - #613

Merged
linroid merged 1 commit into
mainfrom
fix/http-range-fallbacks
Oct 23, 2026
Merged

linroid merged 1 commit into
mainfrom
fix/http-range-fallbacks

Conversation

@linroid

@linroid linroid commented Oct 23, 2026

Copy link
Copy Markdown
Owner

Found while running real downloads with the CLI against a local server that misbehaves the way some file servers and caches do.

What changes

  • Ranges advertised but ignored. A server whose HEAD says Accept-Ranges: bytes but answers ranged GETs with 200 and the whole file failed the download with Not supported: Server returned a different range. KtorHttpEngine now reports that case with a KetchError.Unsupported caused by the new RangeIgnoredException, and HttpDownloadSource restarts the run over one connection from byte zero. A 206 with a different Content-Range still fails, as before.
  • HEAD failing with 500. A HEAD answered with 500 while GET works (handlers that fail on HEAD) failed after three retries without trying the ranged GET probe. 500 now joins 400/403/404/405/501 in RangeSupportDetector.HEAD_REFUSED. If the server is really down, the probe fails with the same 5xx and the usual retries apply.

Verification

  • ketch built from this branch, against a local server:
    • /fake-ranges/ (Accept-Ranges, 200 to ranges): completes, SHA-256 matches. Before: failed.
    • /head/500/ (HEAD 500, GET fine): completes, SHA-256 matches. Before: failed after 3 HEAD retries.
    • /wrong-range/ (206 with another range): still fails with Server returned a different range.
  • ./gradlew :library:core:jvmTest --tests '*HttpDownloadSourceTest*' --tests '*RangeSupportDetectorTest*' --tests '*FailureLoggingTest*' :library:ktor:jvmTest passes. The new download_serverIgnoringAdvertisedRanges_restartsOverOneConnection covers the fallback. download_ignoredRange_failsInsteadOfCorruptingFile is now download_ignoredRange_restartsOverOneConnection: it checks the file is complete and correct, and that the last request asks for the whole file.

A server that advertises Accept-Ranges but answers ranged GETs with the
whole file (200) failed the download with "Server returned a different
range". The engine now reports that case as a RangeIgnoredException, and
HttpDownloadSource restarts the run over one connection from byte zero.

A HEAD answered with 500 while GET works (handlers that fail on HEAD) now
falls back to the ranged GET probe, as 400/403/404/405/501 already did.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-23T13:42:17.257457Z d8f2f8a PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@claude

claude Bot commented Oct 23, 2026

Copy link
Copy Markdown

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@github-actions

Copy link
Copy Markdown
Contributor

Test Results

 2 193 files  ±0   2 221 suites  ±0   57m 22s ⏱️ +41s
15 251 tests +4  14 983 ✅ +4  268 💤 ±0  0 ❌ ±0 
18 602 runs  +4  18 334 ✅ +4  268 💤 ±0  0 ❌ ±0 

Results for commit d8f2f8a. ± Comparison against base commit 94bd6b5.

This pull request removes 1 and adds 5 tests. Note that renamed tests count towards both.
com.linroid.ketch.engine.HttpDownloadIntegrationTest ‑ download_ignoredRange_failsInsteadOfCorruptingFile[jvm]
com.linroid.ketch.engine.HttpDownloadIntegrationTest ‑ download_ignoredRange_restartsOverOneConnection[jvm]
com.linroid.ketch.engine.HttpDownloadSourceTest ‑ download_serverIgnoringAdvertisedRanges_restartsOverOneConnection
com.linroid.ketch.engine.HttpDownloadSourceTest ‑ download_serverIgnoringAdvertisedRanges_restartsOverOneConnection[jvm]
iosSimulatorArm64Test.com.linroid.ketch.engine.HttpDownloadSourceTest ‑ download_serverIgnoringAdvertisedRanges_restartsOverOneConnection[iosSimulatorArm64]
jsNodeTest.com.linroid.ketch.engine.HttpDownloadSourceTest ‑ download_serverIgnoringAdvertisedRanges_restartsOverOneConnection[js, node]

@linroid
linroid merged commit c540080 into main Oct 23, 2026
15 checks passed
@linroid
linroid deleted the fix/http-range-fallbacks branch October 23, 2026 14:15
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