1. cherrypy
  2. CherryPy


visteya  committed df7ba42

Revised the fix for ticket #847, to be similar to the fix which is in the /python3 branch [2272].

This fix is slightly different from the one in /python3. It only sends a 408 if the timeout occurs while in the middle of a request. When no request has been seen on the connection, it does not send a 408; it just closes the connection.

  • Participants
  • Parent commits 51ad18c
  • Branches default

Comments (0)

Files changed (1)

File cherrypy/wsgiserver/__init__.py

View file
  • Ignore whitespace
         self.wsgi_app = wsgi_app
         self.ready = False
+        self.started_request = False
         self.started_response = False
         self.status = ""
         self.outheaders = []
         # (although your TCP stack might suffer for it: cf Apache's history
         # with FIN_WAIT_2).
         request_line = self.rfile.readline()
+        # Set started_request to True so communicate() knows to send 408
+        # from here on out.
+        self.started_request = True
         if not request_line:
             # Force self.ready = False so the connection will close.
             self.ready = False
                 # This order of operations should guarantee correct pipelining.
                 if not req.ready:
+                    # Something went wrong in the parsing (and the server has
+                    # probably already made a simple_response). Return and
+                    # let the conn close.
         except socket.error, e:
             errnum = e.args[0]
-            if req.ready and errnum == 'timed out':
-                if req and not req.sent_headers:
+            if errnum == 'timed out':
+                # Don't send a 408 if there is no outstanding request; only
+                # if we're in the middle of a request.
+                # See http://www.cherrypy.org/ticket/853
+                if req and req.started_request and not req.sent_headers:
                     req.simple_response("408 Request Timeout")
             elif errnum not in socket_errors_to_ignore:
                 if req and not req.sent_headers: