Azure / Azure/azure-sdk-for-python

[azure-core] _aiohttp_body_helper does not decompress Content-Encoding: br (Brotli)

Open
#47,186 0 comments 0 reactions 0 assignees View on GitHub
Azure.Core customer-reported feature-request needs-team-attention
Dominant language
Python
Stars
5.6k
Forks
3.4k
Avg merge
1d 21h
Merged PRs (30d)
193

Description

### Bug Report

**Package:** `azure-core` 1.41.0 (also affects `azure-ai-agentserver-responses` 1.0.0b7)

#### Description

`_aiohttp_body_helper` in `azure.core.utils._pipeline_transport_rest_shared` handles `Content-Encoding: gzip` and `Content-Encoding: deflate`, but does **not** handle `Content-Encoding: br` (Brotli). When an upstream service returns a Brotli-compressed response, the raw compressed bytes pass through to `response.text()`, which then raises `UnicodeDecodeError`.

#### Reproduction

This surfaces when using `azure-ai-agentserver-responses` as a Foundry Hosted Agent. The Foundry storage API (`/storage/history/item_ids`) returns `Content-Encoding: br`. The `FoundryStorageProvider` calls `http_resp.text()` which triggers the decode error.

The `FoundryStorageProvider` intentionally excludes `ContentDecodePolicy` from its pipeline (with a comment noting gzip crashes), so there is no other layer handling decompression.

#### Root Cause

In `azure/core/utils/_pipeline_transport_rest_shared.py`:

```python
def _aiohttp_body_helper(response):
...
enc = response.headers.get("Content-Encoding")
if enc in ("gzip", "deflate"): # <- "br" not handled
...
return response._content # raw Brotli bytes pass through
```

#### Expected Behavior

Brotli responses should be decompressed transparently, matching how gzip/deflate are handled.

#### Suggested Fix

```python
if enc in ("gzip", "deflate"):
...
elif enc == "br":
import brotli
response._content = brotli.decompress(response._content)
response._decompressed_content = True
return response._content
```

(The `brotli` package is already a common transitive dependency via `aiohttp[speedups]`.)

#### Workaround

We monkey-patch `_aiohttp_body_helper` at import time to add Brotli support.

#### Environment

- Python 3.11
- `azure-core==1.41.0`
- `azure-ai-agentserver-responses==1.0.0b7`
- Platform: Azure AI Foundry Hosted Agent (Linux container)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.