Skip to content
Browse files

Issue #284 (reddit#284): added handling of empty content length; chan…

…ged length too big from error 500 to 413 Request Entity Too Large according to RFC 2616-sec10
  • Loading branch information...
1 parent 4070cf7 commit 585f77f8f2c83bcdb2cc8ff6ca5bf460add3f617 @dkuznetsov committed Mar 12, 2012
Showing with 9 additions and 4 deletions.
  1. +9 −4 r2/r2/config/middleware.py
View
13 r2/r2/config/middleware.py
@@ -447,11 +447,16 @@ def __init__(self, app, max_size=1024*500):
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)
+ or not environ[cl_key]):
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)
+ if int(environ[cl_key]) > 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)

0 comments on commit 585f77f

Please sign in to comment.
Something went wrong with that request. Please try again.