fix: compress request bodies with GZIPOutputStream instead of Okio GzipSink - #829
Closed
posthog[bot] wants to merge 2 commits into
Closed
posthog[bot] wants to merge 2 commits into
posthog[bot] wants to merge 2 commits into
Conversation
…ipSink Okio versions before 3.11.0 have a deflater bug (lysine-dev/okio#1608) that can produce corrupt gzip bodies. The SDK does not pin Okio, so apps resolve their own version. Compress with java.util.zip.GZIPOutputStream so the output no longer depends on the Okio version. The body is still buffered, so Content-Length stays set. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Generated-By: PostHog Desktop Task-Id: 0d03b0a3-9ca8-495f-a56c-61411d9b0b54
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Generated-By: PostHog Desktop Task-Id: 0d03b0a3-9ca8-495f-a56c-61411d9b0b54
Contributor
posthog-android Compliance ReportDate: 2026-10-01 17:40:41 UTC ✅ All Tests Passed!46/46 tests passed Capture Tests✅ 29/29 tests passed View Details
Feature_Flags Tests✅ 17/17 tests passed View Details
|
Contributor
|
setting okio min version to 3.11.0 is the solution, we don't need to swap compression |
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.
💡 Motivation and Context
Problem
/flagsand/batch, so the app loses all flags, events and session recordings with no visible error.GzipRequestInterceptorcompresses through OkioGzipSink. The SDK does not pin Okio. It gets Okio only through OkHttp 4.12.0, so the app's build picks the version.compression = NONEopt-out from #793 helps only after someone finds it.Changes
java.util.zip.GZIPOutputStreaminto a byte array. The output no longer depends on the Okio version.Content-Lengthstays set. This replaces the oldforceContentLengthstep.compression, existingContent-Encoding, multipart) do not change.GZIPOutputStream(this PR)Note
The JVM tests resolve Okio 3.6.0, but the bug did not reproduce on the JVM. The new test is a round-trip guard: a large payload must decompress with
java.util.zip.GZIPInputStreamto the original bytes, andContent-Lengthmust match the body. Support reproduced the original bug on an Android 16 emulator only.💚 How did you test it?
GzipRequestInterceptorTest: large payload round trip andContent-Length, plus content type../gradlew :posthog:test: all tests pass, including the existing gzip assertions inPostHogApiTest../gradlew spotlessCheck :posthog:apiCheck: pass. No public API change.📝 Checklist
If releasing new changes
pnpm changesetto generate a changeset file🤖 Agent context
Autonomy: Fully autonomous
NONE.Created with PostHog Desktop from this inbox report.
🤖 Generated with Claude Code
Origin
6a53f45