Emit correct date. In theory
This commit is contained in:
parent
aa3d8398fd
commit
85ff63c32e
2 changed files with 12 additions and 1 deletions
|
|
@ -240,6 +240,7 @@ def send_file(filename_or_fp, mimetype=None, as_attachment=False,
|
||||||
:param conditional: set to `True` to enable conditional responses.
|
:param conditional: set to `True` to enable conditional responses.
|
||||||
:param cache_timeout: the timeout in seconds for the headers.
|
:param cache_timeout: the timeout in seconds for the headers.
|
||||||
"""
|
"""
|
||||||
|
mtime = None
|
||||||
if isinstance(filename_or_fp, basestring):
|
if isinstance(filename_or_fp, basestring):
|
||||||
filename = filename_or_fp
|
filename = filename_or_fp
|
||||||
file = None
|
file = None
|
||||||
|
|
@ -272,11 +273,21 @@ def send_file(filename_or_fp, mimetype=None, as_attachment=False,
|
||||||
else:
|
else:
|
||||||
if file is None:
|
if file is None:
|
||||||
file = open(filename, 'rb')
|
file = open(filename, 'rb')
|
||||||
|
mtime = os.path.getmtime(filename)
|
||||||
data = wrap_file(request.environ, file)
|
data = wrap_file(request.environ, file)
|
||||||
|
|
||||||
rv = current_app.response_class(data, mimetype=mimetype, headers=headers,
|
rv = current_app.response_class(data, mimetype=mimetype, headers=headers,
|
||||||
direct_passthrough=True)
|
direct_passthrough=True)
|
||||||
|
|
||||||
|
# if we know the file modification date, we can store it as the
|
||||||
|
# current time to better support conditional requests. Werkzeug
|
||||||
|
# as of 0.6.1 will override this value however in the conditional
|
||||||
|
# response with the current time. This will be fixed in Werkzeug
|
||||||
|
# with a new release, however many WSGI servers will still emit
|
||||||
|
# a separate date header.
|
||||||
|
if mtime is not None:
|
||||||
|
rv.date = int(mtime)
|
||||||
|
|
||||||
rv.cache_control.public = True
|
rv.cache_control.public = True
|
||||||
if cache_timeout:
|
if cache_timeout:
|
||||||
rv.cache_control.max_age = cache_timeout
|
rv.cache_control.max_age = cache_timeout
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ import tempfile
|
||||||
from logging import StreamHandler
|
from logging import StreamHandler
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from werkzeug import parse_date, parse_options_header
|
from werkzeug import parse_date, parse_options_header, http_date
|
||||||
from werkzeug.exceptions import NotFound
|
from werkzeug.exceptions import NotFound
|
||||||
from jinja2 import TemplateNotFound
|
from jinja2 import TemplateNotFound
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue