diff options
author | Robert Brewer <fumanchu@aminus.org> | 2011-02-25 02:52:13 +0000 |
---|---|---|
committer | Robert Brewer <fumanchu@aminus.org> | 2011-02-25 02:52:13 +0000 |
commit | de07331362a99a788af550ea51ffdd947f7eed72 (patch) | |
tree | 9b9da7caa3d3c78a7aeaee298e535b57c60fbc01 /cherrypy/test/test_conn.py | |
parent | cff8ad794d2d2eecb98203871fe2b88651049fd4 (diff) | |
download | cherrypy-git-de07331362a99a788af550ea51ffdd947f7eed72.tar.gz |
Implemented WSGI 1.0.1's requirement to not send more than Content-Length bytes. Includes 2 tests.
Diffstat (limited to 'cherrypy/test/test_conn.py')
-rw-r--r-- | cherrypy/test/test_conn.py | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/cherrypy/test/test_conn.py b/cherrypy/test/test_conn.py index 29372a4d..4c0a1acb 100644 --- a/cherrypy/test/test_conn.py +++ b/cherrypy/test/test_conn.py @@ -74,6 +74,21 @@ def setup_server(): return ["a" * 1024] * 1024 one_megabyte_of_a.exposed = True + def custom_cl(self, body, cl): + cherrypy.response.headers['Content-Length'] = cl + if not isinstance(body, list): + body = [body] + newbody = [] + for chunk in body: + if isinstance(chunk, unicode): + chunk = chunk.encode('ISO-8859-1') + newbody.append(chunk) + return newbody + custom_cl.exposed = True + # Turn off the encoding tool so it doens't collapse + # our response body and reclaculate the Content-Length. + custom_cl._cp_config = {'tools.encode.on': False} + cherrypy.tree.mount(Root()) cherrypy.config.update({ 'server.max_request_body_size': 1001, @@ -626,7 +641,7 @@ class ConnectionTests(helper.CPWebCase): self.assertStatus(413) conn.close() - def test_Content_Length(self): + def test_Content_Length_in(self): # Try a non-chunked request where Content-Length exceeds # server.max_request_body_size. Assert error before body send. self.persistent = True @@ -643,6 +658,38 @@ class ConnectionTests(helper.CPWebCase): "the maximum allowed bytes.") conn.close() + def test_Content_Length_out_preheaders(self): + # Try a non-chunked response where Content-Length is less than + # the actual bytes in the response body. + self.persistent = True + conn = self.HTTP_CONN + conn.putrequest("GET", "/custom_cl?body=I+have+too+many+bytes&cl=5", + skip_host=True) + conn.putheader("Host", self.HOST) + conn.endheaders() + response = conn.getresponse() + self.status, self.headers, self.body = webtest.shb(response) + self.assertStatus(500) + self.assertBody( + "The requested resource returned more bytes than the " + "declared Content-Length.") + conn.close() + + def test_Content_Length_out_postheaders(self): + # Try a non-chunked response where Content-Length is less than + # the actual bytes in the response body. + self.persistent = True + conn = self.HTTP_CONN + conn.putrequest("GET", "/custom_cl?body=I+too&body=+have+too+many&cl=5", + skip_host=True) + conn.putheader("Host", self.HOST) + conn.endheaders() + response = conn.getresponse() + self.status, self.headers, self.body = webtest.shb(response) + self.assertStatus(200) + self.assertBody("I too") + conn.close() + def test_598(self): remote_data_conn = urlopen('%s://%s:%s/one_megabyte_of_a/' % (self.scheme, self.HOST, self.PORT,)) |