Content-Length - PRoblems?
- From:
- Matt Freeman
- Date:
- 2011-02-25 @ 03:53
Ive added this to my app to work around some issues. It seems when
using gunicorn to host behind Nginx which is hosting HTTPS frontend
combined with unreliable bandwidth in Asia it can cause problems -
seems end prematurely on larger files without knowing. This could of
course just be my crappy ISP
This little hack seems to help. But I think Im doing something wrong,
there must be a design decision as to why Content-Length is omitted?
@app.after_request
def fix_content_length_for_static(res):
# problems behind Nginx with HTTPS
if flask.request.endpoint == 'static':
directory = os.path.dirname(os.path.abspath(__file__))
requested_file = os.path.join(directory,flask.request.path[1:]) #
what about when 404?
res.headers.add("Content-Length",
str(os.path.getsize(requested_file))) # do I need to sanitize this to
stop ../../ attacks
return res
--
w: http://www.mattfreeman.co.uk/ t: http://www.twitter.com/mattcodes