mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 08:11:00 +00:00
use new netlib exceptions
This commit is contained in:
parent
a7291a7e78
commit
f61109db84
@ -1,4 +1,5 @@
|
||||
import time
|
||||
from netlib.exceptions import TcpDisconnect
|
||||
import netlib.tcp
|
||||
|
||||
BLOCKSIZE = 1024
|
||||
@ -62,5 +63,5 @@ def write_values(fp, vals, actions, sofar=0, blocksize=BLOCKSIZE):
|
||||
return True
|
||||
elif a[1] == "inject":
|
||||
send_chunk(fp, a[2], blocksize, 0, len(a[2]))
|
||||
except netlib.tcp.NetLibDisconnect: # pragma: no cover
|
||||
except TcpDisconnect: # pragma: no cover
|
||||
return True
|
||||
|
@ -13,7 +13,8 @@ import OpenSSL.crypto
|
||||
import six
|
||||
|
||||
from netlib import tcp, http, certutils, websockets, socks
|
||||
from netlib.exceptions import HttpException
|
||||
from netlib.exceptions import HttpException, TcpDisconnect, TcpTimeout, TlsException, TcpException, \
|
||||
NetlibException
|
||||
from netlib.http import http1, http2
|
||||
|
||||
import language.http
|
||||
@ -123,7 +124,7 @@ class WebsocketFrameReader(threading.Thread):
|
||||
with self.logger.ctx() as log:
|
||||
try:
|
||||
frm = websockets.Frame.from_file(self.rfile)
|
||||
except tcp.NetLibDisconnect:
|
||||
except TcpDisconnect:
|
||||
return
|
||||
self.frames_queue.put(frm)
|
||||
log("<< %s" % frm.header.human_readable())
|
||||
@ -270,7 +271,7 @@ class Pathoc(tcp.TCPClient):
|
||||
connect_reply.msg,
|
||||
"SOCKS server error"
|
||||
)
|
||||
except (socks.SocksError, tcp.NetLibDisconnect) as e:
|
||||
except (socks.SocksError, TcpDisconnect) as e:
|
||||
raise PathocError(str(e))
|
||||
|
||||
def connect(self, connect_to=None, showssl=False, fp=sys.stdout):
|
||||
@ -301,7 +302,7 @@ class Pathoc(tcp.TCPClient):
|
||||
cipher_list=self.ciphers,
|
||||
alpn_protos=alpn_protos
|
||||
)
|
||||
except tcp.NetLibError as v:
|
||||
except TlsException as v:
|
||||
raise PathocError(str(v))
|
||||
|
||||
self.sslinfo = SSLInfo(
|
||||
@ -394,7 +395,7 @@ class Pathoc(tcp.TCPClient):
|
||||
|
||||
Returns Response if we have a non-ignored response.
|
||||
|
||||
May raise http.HTTPError, tcp.NetLibError
|
||||
May raise a NetlibException
|
||||
"""
|
||||
logger = log.ConnectionLogger(
|
||||
self.fp,
|
||||
@ -414,7 +415,7 @@ class Pathoc(tcp.TCPClient):
|
||||
except HttpException as v:
|
||||
lg("Invalid server response: %s" % v)
|
||||
raise
|
||||
except tcp.NetLibTimeout:
|
||||
except TcpTimeout:
|
||||
if self.ignoretimeout:
|
||||
lg("Timeout (ignored)")
|
||||
return None
|
||||
@ -438,7 +439,7 @@ class Pathoc(tcp.TCPClient):
|
||||
|
||||
Returns Response if we have a non-ignored response.
|
||||
|
||||
May raise http.HTTPError, tcp.NetLibError
|
||||
May raise a NetlibException
|
||||
"""
|
||||
if isinstance(r, basestring):
|
||||
r = language.parse_pathoc(r, self.use_http2).next()
|
||||
@ -495,7 +496,7 @@ def main(args): # pragma: nocover
|
||||
trycount = 0
|
||||
try:
|
||||
p.connect(args.connect_to, args.showssl)
|
||||
except tcp.NetLibError as v:
|
||||
except TcpException as v:
|
||||
print >> sys.stderr, str(v)
|
||||
continue
|
||||
except PathocError as v:
|
||||
@ -523,7 +524,7 @@ def main(args): # pragma: nocover
|
||||
# We consume the queue when we can, so it doesn't build up.
|
||||
for i_ in p.wait(timeout=0, finish=False):
|
||||
pass
|
||||
except (http.HttpError, tcp.NetLibError) as v:
|
||||
except NetlibException:
|
||||
break
|
||||
for i_ in p.wait(timeout=0.01, finish=True):
|
||||
pass
|
||||
|
@ -6,8 +6,8 @@ import threading
|
||||
import urllib
|
||||
|
||||
from netlib import tcp, http, certutils, websockets
|
||||
from netlib.exceptions import HttpException, HttpReadDisconnect
|
||||
from netlib.http import ALPN_PROTO_HTTP1, ALPN_PROTO_H2
|
||||
from netlib.exceptions import HttpException, HttpReadDisconnect, TcpTimeout, TcpDisconnect, \
|
||||
TlsException
|
||||
|
||||
from . import version, app, language, utils, log, protocols
|
||||
import language.http
|
||||
@ -41,7 +41,7 @@ class SSLOptions(object):
|
||||
ssl_options=tcp.SSL_DEFAULT_OPTIONS,
|
||||
ciphers=None,
|
||||
certs=None,
|
||||
alpn_select=ALPN_PROTO_H2,
|
||||
alpn_select=http.ALPN_PROTO_H2,
|
||||
):
|
||||
self.confdir = confdir
|
||||
self.cn = cn
|
||||
@ -247,7 +247,7 @@ class PathodHandler(tcp.BaseHandler):
|
||||
options=self.server.ssloptions.ssl_options,
|
||||
alpn_select=self.server.ssloptions.alpn_select,
|
||||
)
|
||||
except tcp.NetLibError as v:
|
||||
except TlsException as v:
|
||||
s = str(v)
|
||||
self.server.add_log(
|
||||
dict(
|
||||
@ -259,7 +259,7 @@ class PathodHandler(tcp.BaseHandler):
|
||||
return
|
||||
|
||||
alp = self.get_alpn_proto_negotiated()
|
||||
if alp == ALPN_PROTO_H2:
|
||||
if alp == http.ALPN_PROTO_H2:
|
||||
self.protocol = protocols.http2.HTTP2Protocol(self)
|
||||
self.use_http2 = True
|
||||
|
||||
@ -387,7 +387,7 @@ class Pathod(tcp.TCPServer):
|
||||
try:
|
||||
h.handle()
|
||||
h.finish()
|
||||
except tcp.NetLibDisconnect: # pragma: no cover
|
||||
except TcpDisconnect: # pragma: no cover
|
||||
log.write_raw(self.logfp, "Disconnect")
|
||||
self.add_log(
|
||||
dict(
|
||||
@ -396,7 +396,7 @@ class Pathod(tcp.TCPServer):
|
||||
)
|
||||
)
|
||||
return
|
||||
except tcp.NetLibTimeout:
|
||||
except TcpTimeout:
|
||||
log.write_raw(self.logfp, "Timeout")
|
||||
self.add_log(
|
||||
dict(
|
||||
|
@ -1,5 +1,5 @@
|
||||
from netlib import tcp, wsgi
|
||||
from netlib.exceptions import HttpReadDisconnect
|
||||
from netlib.exceptions import HttpReadDisconnect, TlsException
|
||||
from netlib.http import http1, Request
|
||||
from .. import version, language
|
||||
|
||||
@ -61,7 +61,7 @@ class HTTPProtocol(object):
|
||||
options=self.pathod_handler.server.ssloptions.ssl_options,
|
||||
alpn_select=self.pathod_handler.server.ssloptions.alpn_select,
|
||||
)
|
||||
except tcp.NetLibError as v:
|
||||
except TlsException as v:
|
||||
s = str(v)
|
||||
lg(s)
|
||||
return None, dict(type="error", msg=s)
|
||||
|
@ -1,5 +1,6 @@
|
||||
import StringIO
|
||||
from libpathod import log
|
||||
from netlib.exceptions import TcpDisconnect
|
||||
import netlib.tcp
|
||||
|
||||
|
||||
@ -19,6 +20,6 @@ def test_disconnect():
|
||||
try:
|
||||
with l.ctx() as lg:
|
||||
lg("Test")
|
||||
except netlib.tcp.NetLibDisconnect:
|
||||
except TcpDisconnect:
|
||||
pass
|
||||
assert "Test" in outf.getvalue()
|
||||
|
@ -5,7 +5,7 @@ import OpenSSL
|
||||
from mock import Mock
|
||||
|
||||
from netlib import tcp, http, socks
|
||||
from netlib.exceptions import HttpException
|
||||
from netlib.exceptions import HttpException, TcpException, NetlibException
|
||||
from netlib.http import http1, http2
|
||||
|
||||
from libpathod import pathoc, test, version, pathod, language
|
||||
@ -84,7 +84,7 @@ class _TestDaemon:
|
||||
r = r.freeze(language.Settings())
|
||||
try:
|
||||
c.request(r)
|
||||
except (HttpException, tcp.NetLibError):
|
||||
except NetlibException:
|
||||
pass
|
||||
return s.getvalue()
|
||||
|
||||
|
@ -4,7 +4,7 @@ import OpenSSL
|
||||
|
||||
from libpathod import pathod, version
|
||||
from netlib import tcp, http
|
||||
from netlib.exceptions import HttpException
|
||||
from netlib.exceptions import HttpException, TlsException
|
||||
import tutils
|
||||
|
||||
|
||||
@ -264,7 +264,7 @@ class TestDaemonSSL(CommonTests):
|
||||
c.wbufsize = 0
|
||||
c.connect()
|
||||
c.wfile.write("\0\0\0\0")
|
||||
tutils.raises(tcp.NetLibError, c.convert_to_ssl)
|
||||
tutils.raises(TlsException, c.convert_to_ssl)
|
||||
l = self.d.last_log()
|
||||
assert l["type"] == "error"
|
||||
assert "SSL" in l["msg"]
|
||||
|
Loading…
Reference in New Issue
Block a user