mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-22 15:37:45 +00:00
Fix a crash when pathoc connections fail
Use the new handler to tidy this up.
This commit is contained in:
parent
120b6c0b59
commit
11fb217191
127
pathod/pathoc.py
127
pathod/pathoc.py
@ -291,47 +291,43 @@ class Pathoc(tcp.TCPClient):
|
|||||||
if self.use_http2 and not self.ssl:
|
if self.use_http2 and not self.ssl:
|
||||||
raise NotImplementedError("HTTP2 without SSL is not supported.")
|
raise NotImplementedError("HTTP2 without SSL is not supported.")
|
||||||
|
|
||||||
try:
|
ret = tcp.TCPClient.connect(self)
|
||||||
ret = tcp.TCPClient.connect(self)
|
if connect_to:
|
||||||
if connect_to:
|
self.http_connect(connect_to)
|
||||||
self.http_connect(connect_to)
|
|
||||||
|
|
||||||
self.sslinfo = None
|
|
||||||
if self.ssl:
|
|
||||||
try:
|
|
||||||
alpn_protos = [b'http/1.1']
|
|
||||||
if self.use_http2:
|
|
||||||
alpn_protos.append(b'h2')
|
|
||||||
|
|
||||||
self.convert_to_ssl(
|
|
||||||
sni=self.sni,
|
|
||||||
cert=self.clientcert,
|
|
||||||
method=self.ssl_version,
|
|
||||||
options=self.ssl_options,
|
|
||||||
cipher_list=self.ciphers,
|
|
||||||
alpn_protos=alpn_protos
|
|
||||||
)
|
|
||||||
except TlsException as v:
|
|
||||||
raise PathocError(str(v))
|
|
||||||
|
|
||||||
self.sslinfo = SSLInfo(
|
|
||||||
self.connection.get_peer_cert_chain(),
|
|
||||||
self.get_current_cipher(),
|
|
||||||
self.get_alpn_proto_negotiated()
|
|
||||||
)
|
|
||||||
if showssl:
|
|
||||||
print(str(self.sslinfo), file=fp)
|
|
||||||
|
|
||||||
|
self.sslinfo = None
|
||||||
|
if self.ssl:
|
||||||
|
try:
|
||||||
|
alpn_protos = [b'http/1.1']
|
||||||
if self.use_http2:
|
if self.use_http2:
|
||||||
self.protocol.check_alpn()
|
alpn_protos.append(b'h2')
|
||||||
if not self.http2_skip_connection_preface:
|
|
||||||
self.protocol.perform_client_connection_preface()
|
|
||||||
|
|
||||||
if self.timeout:
|
self.convert_to_ssl(
|
||||||
self.settimeout(self.timeout)
|
sni=self.sni,
|
||||||
except Exception:
|
cert=self.clientcert,
|
||||||
self.close()
|
method=self.ssl_version,
|
||||||
raise
|
options=self.ssl_options,
|
||||||
|
cipher_list=self.ciphers,
|
||||||
|
alpn_protos=alpn_protos
|
||||||
|
)
|
||||||
|
except TlsException as v:
|
||||||
|
raise PathocError(str(v))
|
||||||
|
|
||||||
|
self.sslinfo = SSLInfo(
|
||||||
|
self.connection.get_peer_cert_chain(),
|
||||||
|
self.get_current_cipher(),
|
||||||
|
self.get_alpn_proto_negotiated()
|
||||||
|
)
|
||||||
|
if showssl:
|
||||||
|
print(str(self.sslinfo), file=fp)
|
||||||
|
|
||||||
|
if self.use_http2:
|
||||||
|
self.protocol.check_alpn()
|
||||||
|
if not self.http2_skip_connection_preface:
|
||||||
|
self.protocol.perform_client_connection_preface()
|
||||||
|
|
||||||
|
if self.timeout:
|
||||||
|
self.settimeout(self.timeout)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
@ -511,39 +507,40 @@ def main(args): # pragma: no cover
|
|||||||
)
|
)
|
||||||
trycount = 0
|
trycount = 0
|
||||||
try:
|
try:
|
||||||
p.connect(args.connect_to, args.showssl)
|
with p.connect(args.connect_to, args.showssl):
|
||||||
|
for spec in playlist:
|
||||||
|
if args.explain or args.memo:
|
||||||
|
spec = spec.freeze(p.settings)
|
||||||
|
if args.memo:
|
||||||
|
h = hashlib.sha256(spec.spec()).digest()
|
||||||
|
if h not in memo:
|
||||||
|
trycount = 0
|
||||||
|
memo.add(h)
|
||||||
|
else:
|
||||||
|
trycount += 1
|
||||||
|
if trycount > args.memolimit:
|
||||||
|
print("Memo limit exceeded...", file=sys.stderr)
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
ret = p.request(spec)
|
||||||
|
if ret and args.oneshot:
|
||||||
|
return
|
||||||
|
# We consume the queue when we can, so it doesn't build up.
|
||||||
|
for i_ in p.wait(timeout=0, finish=False):
|
||||||
|
pass
|
||||||
|
except NetlibException:
|
||||||
|
break
|
||||||
|
for i_ in p.wait(timeout=0.01, finish=True):
|
||||||
|
pass
|
||||||
except TcpException as v:
|
except TcpException as v:
|
||||||
print(str(v), file=sys.stderr)
|
print(str(v), file=sys.stderr)
|
||||||
continue
|
continue
|
||||||
except PathocError as v:
|
except PathocError as v:
|
||||||
print(str(v), file=sys.stderr)
|
print(str(v), file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
for spec in playlist:
|
|
||||||
if args.explain or args.memo:
|
|
||||||
spec = spec.freeze(p.settings)
|
|
||||||
if args.memo:
|
|
||||||
h = hashlib.sha256(spec.spec()).digest()
|
|
||||||
if h not in memo:
|
|
||||||
trycount = 0
|
|
||||||
memo.add(h)
|
|
||||||
else:
|
|
||||||
trycount += 1
|
|
||||||
if trycount > args.memolimit:
|
|
||||||
print("Memo limit exceeded...", file=sys.stderr)
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
continue
|
|
||||||
try:
|
|
||||||
ret = p.request(spec)
|
|
||||||
if ret and args.oneshot:
|
|
||||||
return
|
|
||||||
# We consume the queue when we can, so it doesn't build up.
|
|
||||||
for i_ in p.wait(timeout=0, finish=False):
|
|
||||||
pass
|
|
||||||
except NetlibException:
|
|
||||||
break
|
|
||||||
for i_ in p.wait(timeout=0.01, finish=True):
|
|
||||||
pass
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
pass
|
pass
|
||||||
if p:
|
if p:
|
||||||
|
@ -218,7 +218,6 @@ def args_pathoc(argv, stdout=sys.stdout, stderr=sys.stderr):
|
|||||||
print(v.marked(), file=stderr)
|
print(v.marked(), file=stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
args.requests = reqs
|
args.requests = reqs
|
||||||
|
|
||||||
return args
|
return args
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user