Changeset 1549
- Timestamp:
- 12/21/06 14:46:12
- Files:
-
- trunk/cherrypy/wsgiserver.py (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/wsgiserver.py
r1546 r1549 108 108 self.connection = connection 109 109 self.rfile = self.connection.rfile 110 self.wfile = self.connection.wfile 110 111 self.environ = connection.environ.copy() 111 112 … … 127 128 # (although your TCP stack might suffer for it: cf Apache's history 128 129 # with FIN_WAIT_2). 129 while True: 130 request_line = self.rfile.readline() 131 if not request_line: 132 # Force self.ready = False so the connection will close. 133 self.ready = False 134 return 135 136 if request_line == "\r\n": 137 # RFC 2616 sec 4.1: "...if the server is reading the protocol 138 # stream at the beginning of a message and receives a CRLF 139 # first, it should ignore the CRLF." 140 # But only ignore one leading line! else we enable a DoS. 130 141 request_line = self.rfile.readline() 131 142 if not request_line: 132 # Force self.ready = False so the connection will close.133 143 self.ready = False 134 144 return 135 elif request_line == "\r\n":136 # "...if the server is reading the protocol stream at the137 # beginning of a message and receives a CRLF first, it138 # should ignore the CRLF." RFC 2616 sec 4.1139 pass140 else:141 break142 145 143 146 server = self.connection.server … … 333 336 return 334 337 338 # Grab any trailer headers 335 339 headers = mimetools.Message(self.rfile) 336 340 self.environ.update(self.parse_headers(headers)) 341 337 342 data.seek(0) 338 343 self.environ["wsgi.input"] = data … … 342 347 def respond(self): 343 348 """Call the appropriate WSGI app and write its iterable output.""" 344 wfile = self. connection.wfile349 wfile = self.wfile 345 350 response = self.wsgi_app(self.environ, self.start_response) 346 351 try: … … 361 366 """Write a simple response back to the client.""" 362 367 status = str(status) 363 wfile = self. connection.wfile368 wfile = self.wfile 364 369 wfile.write("%s %s\r\n" % (self.connection.server.protocol, status)) 365 370 wfile.write("Content-Length: %s\r\n" % len(msg)) … … 399 404 self.sent_headers = True 400 405 self.send_headers() 401 wfile = self. connection.wfile406 wfile = self.wfile 402 407 if self.chunked_write: 403 408 wfile.write(hex(len(chunk))[2:]) … … 437 442 438 443 server = self.connection.server 439 wfile = self. connection.wfile444 wfile = self.wfile 440 445 441 446 if "server" not in hkeys: … … 465 470 return method(self, *args, **kwargs) 466 471 except (SSL.WantReadError, SSL.WantWriteError): 467 # Sleep and try again 472 # Sleep and try again. This is dangerous, because it means 473 # the rest of the stack has no way of differentiating 474 # between a "new handshake" error and "client dropped". 475 # Note this isn't an endless loop: there's a timeout below. 468 476 time.sleep(self.ssl_retry) 469 477 except SSL.SysCallError, e:

