This commit is contained in:
Timothy Jaeryang Baek
2026-04-24 15:35:59 +09:00
parent 6089de0b17
commit 7da6b82471
2 changed files with 27 additions and 5 deletions
+12 -1
View File
@@ -86,6 +86,17 @@ log = logging.getLogger(__name__)
#
##########################################
# Headers that become stale after aiohttp auto-decompresses the upstream
# response body. Forwarding them verbatim causes desktop / programmatic
# clients to attempt decompression of an already-decoded payload, resulting
# in ZlibError. See https://github.com/aio-libs/aiohttp/issues/4462.
_STRIP_PROXY_HEADERS = frozenset({'Content-Encoding', 'Content-Length', 'Transfer-Encoding'})
def _clean_proxy_headers(raw_headers) -> dict:
"""Return a copy of *raw_headers* with stale encoding headers removed."""
return {k: v for k, v in raw_headers.items() if k not in _STRIP_PROXY_HEADERS}
async def send_get_request(url, key=None, user: UserModel = None):
timeout = aiohttp.ClientTimeout(total=AIOHTTP_CLIENT_TIMEOUT_MODEL_LIST)
@@ -163,7 +174,7 @@ async def send_request(
r.raise_for_status()
if stream:
response_headers = dict(r.headers)
response_headers = _clean_proxy_headers(r.headers)
if content_type:
response_headers['Content-Type'] = content_type