Skip to content

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

@eu2pey4

Description

@eu2pey4

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:

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

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    customer-reportedIssues that are reported by GitHub users external to the Azure organization.needs-triageWorkflow: This is a new issue that needs to be triaged to the appropriate team.questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions