|
1 Index: cherrypy/wsgiserver/__init__.py |
|
2 =================================================================== |
|
3 --- cherrypy/wsgiserver/__init__.py (revision 2459) |
|
4 +++ cherrypy/wsgiserver/__init__.py (working copy) |
|
5 @@ -291,6 +291,7 @@ |
|
6 self.wsgi_app = wsgi_app |
|
7 |
|
8 self.ready = False |
|
9 + self.started_request = False |
|
10 self.started_response = False |
|
11 self.status = "" |
|
12 self.outheaders = [] |
|
13 @@ -318,6 +319,9 @@ |
|
14 # (although your TCP stack might suffer for it: cf Apache's history |
|
15 # with FIN_WAIT_2). |
|
16 request_line = self.rfile.readline() |
|
17 + # Set started_request to True so communicate() knows to send 408 |
|
18 + # from here on out. |
|
19 + self.started_request = True |
|
20 if not request_line: |
|
21 # Force self.ready = False so the connection will close. |
|
22 self.ready = False |
|
23 @@ -1169,6 +1173,9 @@ |
|
24 # This order of operations should guarantee correct pipelining. |
|
25 req.parse_request() |
|
26 if not req.ready: |
|
27 + # Something went wrong in the parsing (and the server has |
|
28 + # probably already made a simple response). Return and |
|
29 + # let the conn close. |
|
30 return |
|
31 |
|
32 req.respond() |
|
33 @@ -1178,7 +1185,10 @@ |
|
34 except socket.error, e: |
|
35 errnum = e.args[0] |
|
36 if errnum == 'timed out': |
|
37 - if req and not req.sent_headers: |
|
38 + # Don't send a 408 if there is no oustanding request; only |
|
39 + # if we're in the middle of a request. |
|
40 + # See http://www.cherrypy.org/ticket/853 |
|
41 + if req and req.started_request and not req.sent_headers: |
|
42 req.simple_response("408 Request Timeout") |
|
43 elif errnum not in socket_errors_to_ignore: |
|
44 if req and not req.sent_headers: |