Skip to content

web.FileResponse overrides content_type #2317

Closed
@thelink2012

Description

Long story short

When returning a web.FileResponse from a route, any changes to the content_type member is not taken into account when the file is served. Instead, the file extension is always used to determine the content type of the response.

Expected behaviour

Content-Type header of the response be that of web.FileResponse.content_type when such has been set.

Actual behaviour

Content-Type header is guessed from the file extension of the served file.

Steps to reproduce

Create a route that responds something along the lines of

    response = web.FileResponse('/path/to/some/image.png')
    response.content_type = 'application/octet-stream'
    return response

then curl -i it and notice the Content-Type is image/png.

Your environment

[~]$ uname -mrs
Linux 4.11.9-1-ARCH x86_64
[~]$ python --version
Python 3.6.2
[~]$ pip show aiohttp | grep Version
Version: 2.2.5

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