Skip to content

ClientPayloadError with blank Content-Encoding header #1931

Closed
@ikhlestov

Description

In case response contains blank Content-Encoding header call to await resp.text() will cause an error:

aiohttp.client_exceptions.ClientPayloadError: 400, message='Can not decode content-encoding: '

To reproduce you may use this two scripts - server:

from aiohttp import web
from multidict import MultiDict


async def index(request):
    return web.Response(
        text='Hello Aiohttp!',
        headers=MultiDict({'CONTENT-ENCODING': ''}))

app = web.Application()
app.router.add_get('/', index)
web.run_app(app, host='127.0.0.1', port=8080)

and client:

import asyncio

import aiohttp


async def fetch_page():
    async with aiohttp.ClientSession() as session:
        async with session.get('http://127.0.0.1:8080/') as resp:
            for key, value in resp.headers.items():
                print("%s:" % key, value)
            print(resp.status)
            # Failed on this call
            print(await resp.text())


loop = asyncio.get_event_loop()
loop.run_until_complete(fetch_page())

I don't know exactly why such thing happen, but I'd like to note that on versions of aiohttp prior 2.0 there is no such behavior. Other clients - wget/flask work without any errors.
And also seems that issue #1918 can have the same origin, but there Content-Encoding was provided as deflate.

Env:
Python 3.6.1
aiohttp==2.1.0
async-timeout==1.2.1
chardet==3.0.3
multidict==2.1.6
yarl==0.10.2

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions