Fix double gzip decompression error in aiohttp transport #135
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.
Problem
When using the aiohttp transport with ONVIF cameras that send gzip-compressed responses (e.g., Pelco cameras), users encounter a zlib decompression error:
This issue started appearing in Home Assistant 2025.7.x after switching from httpx to aiohttp for the ONVIF integration.
Root Cause
The issue occurs because:
Content-Encoding: gzipheader in the responseSolution
This PR removes the
Content-Encodingheader when converting aiohttp responses to httpx.Response or requests.Response objects, since aiohttp has already handled the decompression.Changes Made
_filter_headers()helper method to remove theContent-Encodingheader while preserving all other headers (including duplicates)_aiohttp_to_httpx_response()to use the filter_aiohttp_to_requests_response()to use the filter_post_internal()method to share POST logic betweenpost()andpost_xml()post_xml()now directly returns a requests.Response, avoiding unnecessary aiohttp→httpx→requests conversion_httpx_to_requests_response()methodTesting
Two new tests have been added:
test_gzip_content_encoding_header_removed: Verifies that theContent-Encoding: gzipheader is removed after aiohttp decompresses the content, preventing double decompression attemptstest_multiple_duplicate_headers_preserved: Ensures that other headers, including duplicates (e.g., multipleSet-Cookieheaders), are correctly preservedAll existing tests continue to pass, confirming backward compatibility.
Impact
This fix resolves connectivity issues with ONVIF cameras that send gzip-compressed responses, including:
Related Issues
Verification
The fix has been verified with:
Content-Encoding: gzip