Browse Source

Set the content length automatically before calling wrap_file

pull/751/merge
Armin Ronacher 12 years ago
parent
commit
47572c5b40
  1. 1
      flask/helpers.py
  2. 1
      flask/testsuite/basic.py

1
flask/helpers.py

@ -516,6 +516,7 @@ def send_file(filename_or_fp, mimetype=None, as_attachment=False,
if file is None: if file is None:
file = open(filename, 'rb') file = open(filename, 'rb')
mtime = os.path.getmtime(filename) mtime = os.path.getmtime(filename)
headers['Content-Length'] = os.path.getsize(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,

1
flask/testsuite/basic.py

@ -786,6 +786,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
def test_static_files(self): def test_static_files(self):
app = flask.Flask(__name__) app = flask.Flask(__name__)
app.testing = True
rv = app.test_client().get('/static/index.html') rv = app.test_client().get('/static/index.html')
self.assert_equal(rv.status_code, 200) self.assert_equal(rv.status_code, 200)
self.assert_equal(rv.data.strip(), b'<h1>Hello World!</h1>') self.assert_equal(rv.data.strip(), b'<h1>Hello World!</h1>')

Loading…
Cancel
Save