-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
static_file() throws away response headers #580
Comments
So, it's possible to work around the issue like:
But that isn't documented and seems to go against the general 'automagic' feel of this module, IMHO. |
I looked around in the bottle docs, and the However, # Starting at line 2460
def static_file(filename, root,
mimetype='auto',
download=False,
charset='UTF-8'):
""" Open a file in a safe way and return :exc:`HTTPResponse` with status
code 200, 305, 403 or 404. The ``Content-Type``, ``Content-Encoding``,
``Content-Length`` and ``Last-Modified`` headers are set if possible.
Special support for ``If-Modified-Since``, ``Range`` and ``HEAD``
requests.
:param filename: Name or path of the file to send.
:param root: Root path for file lookups. Should be an absolute directory
path.
:param mimetype: Defines the content-type header (default: guess from
file extension)
:param download: If True, ask the browser to open a `Save as...` dialog
instead of opening the file with the associated program. You can
specify a custom filename as a string. If not specified, the
original filename is used (default: False).
:param charset: The charset to use for files with a ``text/*``
mime-type. (default: UTF-8)
"""
... This definitely needs to be added to the docs though. I'll write up a PR documenting this. |
It's in the docs now, and as of version 0.12.19 this still happens. a fix, in static_file, replace the That will solve this issue. |
This fixes bottlepy#580 It seems the current release and the dev versions are different. This dev version adds a headers kwarg, which is not how the rest of bottle works, which uses `response.headers()`. This fixes bottlepy#580, which was already, somewhat fixed, but also changes it to not need a headers kwarg, just copy from the existing response headers. Either way, you can close bottlepy#580 now.
This behavior is 'by design' and documented. static_file() returns a HTTPResponse and that "overrides changes made to the global response object" and "bypasses error handlers". The idea is to have a clean and self-contained way to completely define how the response should look like, and not to worry about the state of the global response object at that time. The correct approach is to manipulate the returned object as you already figured out. Changing that now would be a breaking change unfortunately. PRs to improve the documentation are welcomed of cause. |
Trying to figure out why this toy code wasn't working:
It seems the static_file() method never looks at the original response object.
The text was updated successfully, but these errors were encountered: