fix(decoder): auto-detect gzip magic bytes for responses without Content-Encoding header#914
Draft
Airbyte Support (Airbyte-Support) wants to merge 2 commits intomainfrom
Draft
Conversation
…ent-Encoding header Co-Authored-By: syed.khadeer@airbyte.io <cloud-support@airbyte.io>
Contributor
🤖 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/1771566625-gzip-auto-detect-magic-bytes#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/1771566625-gzip-auto-detect-magic-bytesPR Slash CommandsAirbyte Maintainers can execute the following slash commands on your PR:
|
…Encoding header Co-Authored-By: syed.khadeer@airbyte.io <cloud-support@airbyte.io>
PyTest Results (Full)3 878 tests 3 866 ✅ 10m 57s ⏱️ Results for commit 670e1e3. |
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.
fix(decoder): auto-detect gzip magic bytes for responses without Content-Encoding header
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, and thecreate_gzip_decoderfactory used the inner parser (e.g.CsvParser) as the fallback when headers didn't match — meaning gzip data without the header was never decompressed, producing'utf-8' codec can't decode byte 0x8berrors.Changes:
GzipParser.parse()— now 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.Updates since last revision
test_gzip_parser_auto_detection) with 6 cases covering: gzip CSV/JSONL withoutContent-Encodingheader, non-gzip passthrough,by_headersfallback path, non-streamed mode, and empty data.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 significantly increase memory usage. Consider whether a streaming-friendly approach (e.g., a prefixed stream wrapper) is needed.Content-Encoding: gzipIS present andstream_response=False,response.contentis already decompressed by the requests library.GzipParserthen receives the 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 for your API consumers./v1/salesReportsendpoint (or mock a server that returns gzip bytes withoutContent-Encoding) and confirm the response is correctly decompressed and parsed as TSV/CSV.Notes