Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở Phù hợp với người mới
#47,186 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
76/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
python
Lĩnh vực
backend

Hướng nghiên cứu

Bắt đầu tại azure/core/utils/_pipeline_transport_rest_shared.py, ở _aiohttp_body_helper, và so sánh cách xử lý gzip và deflate hiện có với đường dẫn br được báo cáo. Kiểm tra cách tính khả dụng của Brotli được khai báo, sau đó xác minh rằng phản hồi được mã hóa bằng Brotli được giải nén trước khi response.text() chạy và không còn gây ra UnicodeDecodeError.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Azure.Core customer-reported feature-request needs-team-attention
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)
Ngôn ngữ chính
Python
Star
5.6k
Fork
3.4k
Merge trung bình
2 ngày 1 phút
Pull request đã merge (30 ngày)
218

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Azure/azure-sdk-for-python

Tất cả issue của Azure/azure-sdk-for-python

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.