Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2642,7 +2642,7 @@ def create_gzip_decoder(
return CompositeRawDecoder.by_headers(
[({"Content-Encoding", "Content-Type"}, _compressed_response_types, gzip_parser)],
stream_response=True,
fallback_parser=gzip_parser.inner_parser,
fallback_parser=gzip_parser,
)

@staticmethod
Expand Down
20 changes: 20 additions & 0 deletions unit_tests/sources/declarative/decoders/test_composite_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,26 @@ def test_composite_raw_decoder_csv_parser_without_mocked_response():
thread.join(timeout=5) # ensure thread is cleaned up


def test_gzip_decoder_by_headers_fallback_decompresses_when_no_gzip_header(requests_mock):
requests_mock.register_uri(
"GET",
"https://airbyte.io/",
content=generate_csv(should_compress=True),
headers={"Content-Type": "binary/octet-stream"},
)
response = requests.get("https://airbyte.io/", stream=True)

gzip_parser = GzipParser(inner_parser=CsvParser())
composite_raw_decoder = CompositeRawDecoder.by_headers(
[({"Content-Encoding", "Content-Type"}, {"gzip", "application/gzip"}, gzip_parser)],
stream_response=True,
fallback_parser=gzip_parser,
)
parsed_records = list(composite_raw_decoder.decode(response))
assert len(parsed_records) == 3
assert parsed_records[0] == {"id": "1", "name": "John", "age": "28"}


def test_given_response_already_consumed_when_decode_then_no_data_is_returned(requests_mock):
requests_mock.register_uri(
"GET", "https://airbyte.io/", content=json.dumps({"test": "test"}).encode()
Expand Down
Loading