Commits

Robert Brewer  committed b501837

Test and fix for #810 (Add 408 responses).

  • Participants
  • Parent commits b013de5

Comments (0)

Files changed (2)

File cherrypy/test/test_conn.py

             # 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()
             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:

File cherrypy/wsgiserver/__init__.py

         
         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())