Add last_modified arg for send_file

Enhancement: Add last_modified arg of type DateTime to send_file.

Fixes pallets/flask#1321
This commit is contained in:
Prachi Shirish Khadke 2016-06-02 13:00:42 -07:00 committed by David Lord
parent 64a37bb9b7
commit af515cc7ea
2 changed files with 22 additions and 4 deletions

View file

@ -18,7 +18,7 @@ from logging import StreamHandler
from werkzeug.exceptions import BadRequest, NotFound
from werkzeug.http import parse_cache_control_header, parse_options_header
from werkzeug.http import http_date
from flask._compat import StringIO, text_type
from flask._compat import StringIO, text_type, PY2
def has_encoding(name):
@ -349,6 +349,17 @@ class TestSendfile(object):
assert rv.mimetype == 'text/html'
rv.close()
def test_send_file_last_modified(self):
app = flask.Flask(__name__)
with app.test_request_context():
dtm = datetime.datetime.now()
rv = flask.send_file('static/index.html', last_modified=dtm)
if PY2:
assert rv.last_modified == int(dtm.strftime("%s"))
else:
assert rv.last_modified == dtm.timestamp()
rv.close()
def test_send_file_object(self):
app = flask.Flask(__name__)