mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-27 07:48:16 -05:00
Return more correct HTTP status for Content-Length
* 413 Request Entity Too Large for "too big" case * 411 Length Required for missing header case * 400 Bad Request for invalid header case
This commit is contained in:
committed by
Keith Mitchell
parent
b1a53e57d3
commit
92287f219d
@@ -447,11 +447,24 @@ class LimitUploadSize(object):
|
||||
def __call__(self, environ, start_response):
|
||||
cl_key = 'CONTENT_LENGTH'
|
||||
if environ['REQUEST_METHOD'] == 'POST':
|
||||
if ((cl_key not in environ)
|
||||
or int(environ[cl_key]) > self.max_size):
|
||||
if cl_key not in environ:
|
||||
r = Response()
|
||||
r.status_code = 500
|
||||
r.content = '<html><head></head><body><script type="text/javascript">parent.too_big();</script>request too big</body></html>'
|
||||
r.status_code = 411
|
||||
r.content = '<html><head></head><body>length required</body></html>'
|
||||
return r(environ, start_response)
|
||||
|
||||
try:
|
||||
cl_int = int(environ[cl_key])
|
||||
except ValueError:
|
||||
r = Response()
|
||||
r.status_code = 400
|
||||
r.content = '<html><head></head><body>bad request</body></html>'
|
||||
return r(environ, start_response)
|
||||
|
||||
if cl_int > self.max_size:
|
||||
r = Response()
|
||||
r.status_code = 413
|
||||
r.content = '<html><head></head><body><script type="text/javascript">parent.too_big();</script>request entity too large</body></html>'
|
||||
return r(environ, start_response)
|
||||
|
||||
return self.app(environ, start_response)
|
||||
|
||||
Reference in New Issue
Block a user