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

FileResponse clobbers status #4106

Closed
btimby opened this issue Sep 26, 2019 · 1 comment
Closed

FileResponse clobbers status #4106

btimby opened this issue Sep 26, 2019 · 1 comment

Comments

@btimby
Copy link
Contributor

btimby commented Sep 26, 2019

Long story short

I am using FileResponse to return a file. However, if I pass a status to __init__() it is overwritten with 200 in FileResponse.prepare(). This looks like a bug as it should probably only overwrite this value when handling a range request.

Relevant lines:
https://github.com/aio-libs/aiohttp/blob/master/aiohttp/web_fileresponse.py#L248
https://github.com/aio-libs/aiohttp/blob/master/aiohttp/web_fileresponse.py#L322

I will open a PR shortly.

Expected behaviour

I expect the HTTP status code I desire to be emitted to the client.

Actual behaviour

HTTP status is always 200.

Steps to reproduce

import os
import tempfile
import aiohttp

def handler(request):
    fd, path = tempfile.mkstemp()
    os.close(fd)
    response = web.FileResponse(path, status=203)
    return response

if __name__ == '__main__':
    app = web.Application()
    app.add_routes([web.get('/', handler)])
    web.run_app(app, port=3000)

Your environment

Ubuntu 18.04, I am using aiohttp==3.6.1, but master has the same issue.

@asvetlov
Copy link
Member

Fixed by #4107

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants