Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] Compression not working as expected #450

Closed
sk- opened this issue Jul 30, 2015 · 3 comments
Closed

[bug] Compression not working as expected #450

sk- opened this issue Jul 30, 2015 · 3 comments
Assignees
Labels
Milestone

Comments

@sk-
Copy link

sk- commented Jul 30, 2015

Calling enable_compression on a response does not work as expected at all. The response misses data or the whole handler hangs.

The app below reproduces the problem:

import asyncio

import aiohttp.web


def run_app(app, host='0.0.0.0', port=8080):
    """Run an app locally."""
    loop = asyncio.get_event_loop()
    handler = app.make_handler()
    f = loop.create_server(handler, host, port)
    srv = loop.run_until_complete(f)

    if host == '0.0.0.0':
        host = '127.0.0.1'
    print(' * Running on http://{host}:{port}/ (Press CTRL+C to quit)'.format(
        host=host, port=port))

    try:
        loop.run_forever()
    except KeyboardInterrupt:
        pass
    finally:
        loop.run_until_complete(handler.finish_connections(1.0))
        srv.close()
        loop.run_until_complete(srv.wait_closed())
        loop.run_until_complete(app.finish())
    loop.close()


@asyncio.coroutine
def bug_response_small(unused_request):
    r = aiohttp.web.Response(body=b'foo')
    r.enable_compression()
    return r

@asyncio.coroutine
def bug_response_large(unused_request):
    r = aiohttp.web.Response(body=b'foo' * 100)
    r.enable_compression()
    return r

if __name__ == '__main__':
    app = aiohttp.web.Application()
    app.router.add_route('GET', '/response/small', bug_response_small)
    app.router.add_route('GET', '/response/large', bug_response_large)
    run_app(app)

Run the app and then execute the following:

~$ curl localhost:8080/response/small -H "Accept-Encoding: none" --compressed
foo

~$ curl localhost:8080/response/small -H "Accept-Encoding: gzip" --compressed

<NO RESPONSE>
~$ curl localhost:8080/response/small -H "Accept-Encoding: deflate" --compressed
fo
<MISSING 1 CHARACTER>

~$ curl localhost:8080/response/large -H "Accept-Encoding: none" --compressed
foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoo

~$ curl localhost:8080/response/large -H "Accept-Encoding: gzip" --compressed
^C
<APP HANGS>

~$ curl localhost:8080/response/large -H "Accept-Encoding: deflate" --compressed
^C
<APP HANGS>
@asvetlov
Copy link
Member

asvetlov commented Aug 4, 2015

Thanks for report.

@fafhrd91 do you have a time to take a look?

@asvetlov asvetlov added this to the 0.18 milestone Aug 11, 2015
@asvetlov
Copy link
Member

It was because enabling compression did not remove Content-Length header.
Fixed by 1f3a6be

@asvetlov asvetlov modified the milestones: 0.17.3, 0.18 Aug 11, 2015
@asvetlov asvetlov self-assigned this Aug 11, 2015
@lock
Copy link

lock bot commented Oct 29, 2019

This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related bugs.

If you feel like there's important points made in this discussion,
please include those exceprts into that new issue.

@lock lock bot added the outdated label Oct 29, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants