mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-26 02:10:59 +00:00
Fine-tune threading and fix an exception.
This commit is contained in:
parent
efe11a0782
commit
eb93cc22ce
@ -9,6 +9,7 @@ class ReplayConnection:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
# begin nocover
|
||||||
class ReplayThread(threading.Thread):
|
class ReplayThread(threading.Thread):
|
||||||
def __init__(self, flow, masterq):
|
def __init__(self, flow, masterq):
|
||||||
self.flow, self.masterq = flow, masterq
|
self.flow, self.masterq = flow, masterq
|
||||||
@ -22,6 +23,7 @@ class ReplayThread(threading.Thread):
|
|||||||
except proxy.ProxyError, v:
|
except proxy.ProxyError, v:
|
||||||
err = proxy.Error(self.flow.connection, v.msg)
|
err = proxy.Error(self.flow.connection, v.msg)
|
||||||
err.send(self.masterq)
|
err.send(self.masterq)
|
||||||
|
# end nocover
|
||||||
|
|
||||||
|
|
||||||
class Flow:
|
class Flow:
|
||||||
|
@ -305,9 +305,11 @@ class ServerConnection:
|
|||||||
|
|
||||||
def read_response(self):
|
def read_response(self):
|
||||||
proto = self.rfile.readline()
|
proto = self.rfile.readline()
|
||||||
|
if not proto:
|
||||||
|
raise ProxyError(200, "Blank server response.")
|
||||||
parts = proto.strip().split(" ", 2)
|
parts = proto.strip().split(" ", 2)
|
||||||
if not len(parts) == 3:
|
if not len(parts) == 3:
|
||||||
raise ProxyError(200, "Invalid server response.")
|
raise ProxyError(200, "Invalid server response: %s."%proto)
|
||||||
proto, code, msg = parts
|
proto, code, msg = parts
|
||||||
code = int(code)
|
code = int(code)
|
||||||
headers = utils.Headers()
|
headers = utils.Headers()
|
||||||
@ -415,6 +417,7 @@ class ProxyHandler(SocketServer.StreamRequestHandler):
|
|||||||
self.terminate(self.connection, self.wfile, self.rfile)
|
self.terminate(self.connection, self.wfile, self.rfile)
|
||||||
|
|
||||||
def send_error(self, code, body):
|
def send_error(self, code, body):
|
||||||
|
try:
|
||||||
import BaseHTTPServer
|
import BaseHTTPServer
|
||||||
response = BaseHTTPServer.BaseHTTPRequestHandler.responses[code][0]
|
response = BaseHTTPServer.BaseHTTPRequestHandler.responses[code][0]
|
||||||
self.wfile.write("HTTP/1.0 %s %s\r\n" % (code, response))
|
self.wfile.write("HTTP/1.0 %s %s\r\n" % (code, response))
|
||||||
@ -426,10 +429,13 @@ class ProxyHandler(SocketServer.StreamRequestHandler):
|
|||||||
self.wfile.flush()
|
self.wfile.flush()
|
||||||
self.wfile.close()
|
self.wfile.close()
|
||||||
self.rfile.close()
|
self.rfile.close()
|
||||||
|
except IOError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
ServerBase = SocketServer.ThreadingTCPServer
|
ServerBase = SocketServer.ThreadingTCPServer
|
||||||
class ProxyServer(ServerBase):
|
class ProxyServer(ServerBase):
|
||||||
|
request_queue_size = 20
|
||||||
allow_reuse_address = True
|
allow_reuse_address = True
|
||||||
def __init__(self, port):
|
def __init__(self, port):
|
||||||
self.port = port
|
self.port = port
|
||||||
|
Loading…
Reference in New Issue
Block a user