fix(decoder): auto-detect gzip magic bytes in GzipParser for APIs without Content-Encoding header#967
Draft
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
Draft
Conversation
…hout Content-Encoding header GzipParser now checks for gzip magic bytes (0x1f 0x8b) before attempting decompression. If data is not gzip-compressed, it passes through to the inner parser unchanged. This fixes APIs like Apple App Store Connect that return gzip bodies without Content-Encoding headers. Also updates create_gzip_decoder() to use gzip_parser (with auto-detection) as the fallback parser instead of gzip_parser.inner_parser. Co-Authored-By: bot_apk <apk@cognition.ai>
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
👋 Greetings, Airbyte Team Member!Here are some helpful tips and reminders for your convenience. 💡 Show Tips and TricksTesting This CDK VersionYou can test this version of the CDK using the following: # Run the CLI from this branch:
uvx 'git+https://github.com/airbytehq/airbyte-python-cdk.git@devin/1774625405-fix-gzip-decoder-auto-detect#egg=airbyte-python-cdk[dev]' --help
# Update a connector to use the CDK from this branch ref:
cd airbyte-integrations/connectors/source-example
poe use-cdk-branch devin/1774625405-fix-gzip-decoder-auto-detectPR Slash CommandsAirbyte Maintainers can execute the following slash commands on your PR:
|
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.
Summary
Some APIs (notably Apple App Store Connect
/v1/salesReports) return gzip-compressed response bodies without setting theContent-Encoding: gzipheader. The existingGzipParserunconditionally assumed gzip input, andcreate_gzip_decoder()used the inner parser (e.g.CsvParser) as the fallback when headers didn't match — so gzip data without the header was never decompressed, producing'utf-8' codec can't decode byte 0x8berrors.Changes:
GzipParser.parse()— reads the first 2 bytes and checks for gzip magic bytes (\x1f\x8b). If present, decompresses; otherwise passes data through to the inner parser unchanged.create_gzip_decoder()— usesgzip_parser(with auto-detection) instead ofgzip_parser.inner_parseras both the default parser in builder mode and the fallback in production mode.Resolves https://github.com/airbytehq/oncall/issues/11809:
Related: #914, #909, #895, #892
Review & Testing Checklist for Human
GzipParser.parse()now callsdata.read()to buffer the entire response into aBytesIO. The old code streamed throughgzip.GzipFile(fileobj=data)directly. For very large responses in production mode (stream_response=True), this could increase memory usage. Consider whether a streaming-friendly approach (e.g., a peek/wrapper that avoids full buffering) is needed for connectors that transfer large files.Content-Encoding: gzipIS present andstream_response=False, the requests library already decompressesresponse.content.GzipParserthen receives decompressed bytes — the magic-byte check should correctly identify this as non-gzip and pass through. However, if decompressed content happens to start with\x1f\x8bbytes, it would be incorrectly re-decompressed. Assess whether this is a realistic risk./v1/salesReports(or mock a server returning gzip bytes withoutContent-Encoding) and confirm the response is correctly decompressed and parsed.Notes
GzipDecoder.by_headersmode, and non-streamed mode. All 40 decoder tests pass locally.Link to Devin session: https://app.devin.ai/sessions/e68cbb230b3b491aae68837d3dea4f26