diff options
author | Robert Brewer <fumanchu@aminus.org> | 2008-05-25 22:02:41 +0000 |
---|---|---|
committer | Robert Brewer <fumanchu@aminus.org> | 2008-05-25 22:02:41 +0000 |
commit | cb21ffacfb3ce892b205ab52a26f5edb4f9455e8 (patch) | |
tree | 636962f2462f3bdddec51580b1f5d769bf7b78d8 | |
parent | b0582075e838d74eba25645eaef286cbfeef35be (diff) | |
download | cherrypy-cb21ffacfb3ce892b205ab52a26f5edb4f9455e8.tar.gz |
Test and fix for #810 (Add 408 responses).
-rw-r--r-- | cherrypy/test/test_conn.py | 25 | ||||
-rw-r--r-- | cherrypy/wsgiserver/__init__.py | 5 |
2 files changed, 26 insertions, 4 deletions
diff --git a/cherrypy/test/test_conn.py b/cherrypy/test/test_conn.py index 6c940ed3..4f1a7380 100644 --- a/cherrypy/test/test_conn.py +++ b/cherrypy/test/test_conn.py @@ -223,9 +223,6 @@ class ConnectionTests(helper.CPWebCase): # Make an initial request self.persistent = True conn = self.HTTP_CONN - # Make the socket nonblocking so it can timeout -## conn.connect() -## conn.sock.settimeout(0.1) conn.putrequest("GET", "/", skip_host=True) conn.putheader("Host", self.HOST) conn.endheaders() @@ -278,6 +275,28 @@ class ConnectionTests(helper.CPWebCase): self.assertEqual(response.status, 200) self.body = response.read() self.assertBody(pov) + + # Make another request on the same socket, + # but timeout on the headers + conn.send('GET /hello HTTP/1.1') + # Wait for our socket timeout + time.sleep(timeout * 2) + response = conn.response_class(conn.sock, method="GET") + response.begin() + self.assertEqual(response.status, 408) + conn.close() + + # Retry the request on a new connection, which should work + self.persistent = True + conn = self.HTTP_CONN + conn.putrequest("GET", "/", skip_host=True) + conn.putheader("Host", self.HOST) + conn.endheaders() + response = conn.response_class(conn.sock, method="GET") + response.begin() + self.assertEqual(response.status, 200) + self.body = response.read() + self.assertBody(pov) conn.close() finally: if old_timeout is not None: diff --git a/cherrypy/wsgiserver/__init__.py b/cherrypy/wsgiserver/__init__.py index 3de27ea8..7792683f 100644 --- a/cherrypy/wsgiserver/__init__.py +++ b/cherrypy/wsgiserver/__init__.py @@ -978,7 +978,10 @@ class HTTPConnection(object): except socket.error, e: errnum = e.args[0] - if errnum not in socket_errors_to_ignore: + if errnum == 'timed out': + if req: + req.simple_response("408 Request Timeout") + elif errnum not in socket_errors_to_ignore: if req: req.simple_response("500 Internal Server Error", format_exc()) |