diff --git a/libmproxy/flow.py b/libmproxy/flow.py index 296b67388..3548bf3e7 100644 --- a/libmproxy/flow.py +++ b/libmproxy/flow.py @@ -9,6 +9,7 @@ class ReplayConnection: pass +# begin nocover class ReplayThread(threading.Thread): def __init__(self, flow, masterq): self.flow, self.masterq = flow, masterq @@ -22,6 +23,7 @@ class ReplayThread(threading.Thread): except proxy.ProxyError, v: err = proxy.Error(self.flow.connection, v.msg) err.send(self.masterq) +# end nocover class Flow: diff --git a/libmproxy/proxy.py b/libmproxy/proxy.py index 5e8da3e4c..9715bb5a8 100644 --- a/libmproxy/proxy.py +++ b/libmproxy/proxy.py @@ -305,9 +305,11 @@ class ServerConnection: def read_response(self): proto = self.rfile.readline() + if not proto: + raise ProxyError(200, "Blank server response.") parts = proto.strip().split(" ", 2) if not len(parts) == 3: - raise ProxyError(200, "Invalid server response.") + raise ProxyError(200, "Invalid server response: %s."%proto) proto, code, msg = parts code = int(code) headers = utils.Headers() @@ -415,21 +417,25 @@ class ProxyHandler(SocketServer.StreamRequestHandler): self.terminate(self.connection, self.wfile, self.rfile) def send_error(self, code, body): - import BaseHTTPServer - response = BaseHTTPServer.BaseHTTPRequestHandler.responses[code][0] - self.wfile.write("HTTP/1.0 %s %s\r\n" % (code, response)) - self.wfile.write("Server: %s\r\n"%NAME) - self.wfile.write("Content-type: text/html\r\n") - self.wfile.write("\r\n") - self.wfile.write('\n%d %s\n\n' - '\n%s\n\n' % (code, response, body)) - self.wfile.flush() - self.wfile.close() - self.rfile.close() + try: + import BaseHTTPServer + response = BaseHTTPServer.BaseHTTPRequestHandler.responses[code][0] + self.wfile.write("HTTP/1.0 %s %s\r\n" % (code, response)) + self.wfile.write("Server: %s\r\n"%NAME) + self.wfile.write("Content-type: text/html\r\n") + self.wfile.write("\r\n") + self.wfile.write('\n%d %s\n\n' + '\n%s\n\n' % (code, response, body)) + self.wfile.flush() + self.wfile.close() + self.rfile.close() + except IOError: + pass ServerBase = SocketServer.ThreadingTCPServer class ProxyServer(ServerBase): + request_queue_size = 20 allow_reuse_address = True def __init__(self, port): self.port = port