view components/python/cherrypy/patches/cp-ticket-847.patch @ 394:dffc35307ef2

7051374 3rd party libraries in IPS gate should move to userland 7008441 Problem with utility/python 7066296 Bump LDTP to v2.1.1
author Erik Trauschke <Erik.Trauschke@oracle.com>
date Wed, 13 Jul 2011 12:43:29 -0700
parents
children
line wrap: on
line source

Index: cherrypy/wsgiserver/__init__.py
===================================================================
--- cherrypy/wsgiserver/__init__.py	(revision 2459)
+++ cherrypy/wsgiserver/__init__.py	(working copy)
@@ -291,6 +291,7 @@
         self.wsgi_app = wsgi_app
         
         self.ready = False
+        self.started_request = False
         self.started_response = False
         self.status = ""
         self.outheaders = []
@@ -318,6 +319,9 @@
         # (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
@@ -1169,6 +1173,9 @@
                 # This order of operations should guarantee correct pipelining.
                 req.parse_request()
                 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.
                     return
                 
                 req.respond()
@@ -1178,7 +1185,10 @@
         except socket.error, e:
             errnum = e.args[0]
             if errnum == 'timed out':
-                if req and not req.sent_headers:
+                # Don't send a 408 if there is no oustanding 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: