Repository navigation
fix(http): ask for identity encoding so compressed lengths never truncate files - #623
Merged
Merged
Conversation
…cate files Downloading https://api.github.com/repos/linroid/Ketch/releases saved the first 20 KB of a 194 KB JSON. OkHttp asks for gzip on requests without a range, a HEAD included, so the server reported its compressed length; the ranged GETs that followed, which OkHttp never compresses, got the plain bytes, and Ketch stopped at the compressed size. Servers that compress on the fly (nginx gzip, GitHub's API) did this for any text, JSON, CSV, HTML or SVG file. KtorHttpEngine now sends Accept-Encoding: identity unless the caller names an encoding, as download managers such as wget do.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Found while downloading real HTTPS resources with the CLI: files were silently truncated.
Why
On the JVM and Android, HTTPS goes through OkHttp, which adds
Accept-Encoding: gzipto every request without aRange. Ketch'sHEADis one of them:HEAD→ the server compresses on the fly and reports the compressedContent-Length(20,142), plusAccept-Ranges: bytes.Any server that compresses on the fly (nginx
gzip on, GitHub's API, many CDNs) causes this for text, JSON, CSV, HTML, XML or SVG files. iOS'sNSURLSessionadds gzip by default too.What changes
KtorHttpEngine.requestHeadersaddsAccept-Encoding: identityunless the caller names an encoding, as wget does. Lengths, ranges and bytes then all describe the same representation. Callers that pass their ownAccept-Encodingkeep it. Cross-origin redirects already keepAccept-Encoding.Verification
ketchfrom this branch on the GitHub API URL saves the whole document, which parses as JSON with its 5 entries. Before: 20,142 bytes that failed to parse.curl --compressed, and binary release assets are unchanged.KtorHttpEngineEncodingTest:HEADandGETask foridentity; a caller's ownaccept-encoding: gzipis kept../gradlew :library:ktor:jvmTest :library:core:jvmTest --tests '*Http*' --tests '*Headers*'passes.