Skip to content

FileResponse clobbers status #4106

Closed
Closed
@btimby

Description

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.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions