Changeset 1920
- Timestamp:
- 03/14/08 10:14:57
- Files:
-
- trunk/cherrypy/wsgiserver/__init__.py (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/wsgiserver/__init__.py
r1915 r1920 274 274 max_request_body_size = 0 275 275 276 def __init__(self, send, environ, wsgi_app):276 def __init__(self, wfile, environ, wsgi_app): 277 277 self.rfile = environ['wsgi.input'] 278 self. send = send278 self.wfile = wfile 279 279 self.environ = environ.copy() 280 280 self.wsgi_app = wsgi_app … … 554 554 self.send_headers() 555 555 if self.chunked_write: 556 self. sendall("0\r\n\r\n")556 self.wfile.sendall("0\r\n\r\n") 557 557 558 558 def simple_response(self, status, msg=""): … … 571 571 if msg: 572 572 buf.append(msg) 573 self. sendall("".join(buf))573 self.wfile.sendall("".join(buf)) 574 574 575 575 def start_response(self, status, headers, exc_info = None): … … 604 604 if self.chunked_write and chunk: 605 605 buf = [hex(len(chunk))[2:], "\r\n", chunk, "\r\n"] 606 self. sendall("".join(buf))606 self.wfile.sendall("".join(buf)) 607 607 else: 608 self.sendall(chunk) 609 610 def sendall(self, data): 611 """Sendall for non-blocking sockets.""" 612 while data: 613 try: 614 bytes_sent = self.send(data) 615 data = data[bytes_sent:] 616 except socket.error, e: 617 if e.args[0] not in socket_errors_nonblocking: 618 raise 608 self.wfile.sendall(chunk) 619 609 620 610 def send_headers(self): … … 683 673 raise 684 674 buf.append("\r\n") 685 self. sendall("".join(buf))675 self.wfile.sendall("".join(buf)) 686 676 687 677 … … 701 691 while data: 702 692 try: 703 bytes_sent = self. _sock.send(data)693 bytes_sent = self.send(data) 704 694 data = data[bytes_sent:] 705 695 except socket.error, e: … … 872 862 873 863 if is_reader and thirdarg == 'ssl handshake failure': 864 # Return "" to simulate EOF which will close the conn. 874 865 return "" 875 866 if thirdarg == 'http request': 876 867 # The client is talking HTTP to an HTTPS server. 877 868 raise NoSSLError() 878 raise 869 if is_reader and thirdarg == 'decryption failed or bad record mac': 870 # Return "" to simulate EOF which will close the conn. 871 return "" 872 else: 873 raise 879 874 except: 880 875 raise 876 881 877 if time.time() - start > self.ssl_timeout: 882 878 raise socket.timeout("timed out") … … 923 919 if SSL and isinstance(sock, SSL.ConnectionType): 924 920 timeout = sock.gettimeout() 925 self.rfile = SSL_fileobject(sock, "r ", self.rbufsize)921 self.rfile = SSL_fileobject(sock, "rb", self.rbufsize) 926 922 self.rfile.ssl_timeout = timeout 927 self.send = self.rfile.send 923 self.wfile = SSL_fileobject(sock, "wb", -1) 924 self.wfile.ssl_timeout = timeout 928 925 else: 929 926 self.rfile = CP_fileobject(sock, "rb", self.rbufsize) 930 self. send = sock.send927 self.wfile = CP_fileobject(sock, "wb", -1) 931 928 932 929 # Wrap wsgi.input but not HTTPConnection.rfile itself. … … 944 941 # get written to the previous request. 945 942 req = None 946 req = self.RequestHandlerClass(self. send, self.environ,943 req = self.RequestHandlerClass(self.wfile, self.environ, 947 944 self.wsgi_app) 948 945 … … 971 968 raise 972 969 except NoSSLError: 973 # Unwrap our send974 req. send = self.socket._sock.send970 # Unwrap our wfile 971 req.wfile = CP_fileobject(self.socket, "wb", -1) 975 972 req.simple_response("400 Bad Request", 976 973 "The client sent a plain HTTP request, but " 977 974 "this server only speaks HTTPS on this port.") 978 975 except Exception, e: 976 fd = open("ssl_errors.txt", "a") 977 fd.write("2" * 80) 978 fd.write("\n") 979 fd.write(format_exc()) 979 980 if req: 980 fd = open("ssl_errors.txt", "a")981 fd.write("2" * 80)982 fd.write("\n")983 fd.write(format_exc())984 981 req.simple_response("500 Internal Server Error", format_exc()) 985 982

