mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-30 03:14:22 +00:00
100% test coverage
This commit is contained in:
parent
97fdb9ef0c
commit
332832278f
@ -293,35 +293,19 @@ class Pathoc(tcp.TCPClient):
|
|||||||
return
|
return
|
||||||
yield frm
|
yield frm
|
||||||
|
|
||||||
def websocket_get_frame(self, frame):
|
|
||||||
"""
|
|
||||||
Called when a frame is received from the server.
|
|
||||||
"""
|
|
||||||
pass
|
|
||||||
|
|
||||||
def websocket_send_frame(self, r):
|
def websocket_send_frame(self, r):
|
||||||
"""
|
"""
|
||||||
Sends a single websocket frame.
|
Sends a single websocket frame.
|
||||||
"""
|
"""
|
||||||
with self.log() as log:
|
with self.log() as log:
|
||||||
if isinstance(r, basestring):
|
|
||||||
r = language.parse_pathoc(r).next()
|
|
||||||
log(">> %s" % r)
|
log(">> %s" % r)
|
||||||
try:
|
|
||||||
language.serve(r, self.wfile, self.settings)
|
language.serve(r, self.wfile, self.settings)
|
||||||
self.wfile.flush()
|
self.wfile.flush()
|
||||||
except tcp.NetLibTimeout:
|
|
||||||
if self.ignoretimeout:
|
|
||||||
self.log("Timeout (ignored)")
|
|
||||||
return None
|
|
||||||
raise
|
|
||||||
|
|
||||||
def websocket_start(self, r, limit=None):
|
def websocket_start(self, r):
|
||||||
"""
|
"""
|
||||||
Performs an HTTP request, and attempts to drop into websocket
|
Performs an HTTP request, and attempts to drop into websocket
|
||||||
connection.
|
connection.
|
||||||
|
|
||||||
limit: Disconnect after receiving N server frames.
|
|
||||||
"""
|
"""
|
||||||
resp = self.http(r)
|
resp = self.http(r)
|
||||||
if resp.status_code == 101:
|
if resp.status_code == 101:
|
||||||
@ -348,8 +332,6 @@ class Pathoc(tcp.TCPClient):
|
|||||||
May raise http.HTTPError, tcp.NetLibError
|
May raise http.HTTPError, tcp.NetLibError
|
||||||
"""
|
"""
|
||||||
with self.log() as log:
|
with self.log() as log:
|
||||||
if isinstance(r, basestring):
|
|
||||||
r = language.parse_pathoc(r).next()
|
|
||||||
log(">> %s" % r)
|
log(">> %s" % r)
|
||||||
resp, req = None, None
|
resp, req = None, None
|
||||||
try:
|
try:
|
||||||
@ -395,7 +377,7 @@ class Pathoc(tcp.TCPClient):
|
|||||||
r = language.parse_pathoc(r).next()
|
r = language.parse_pathoc(r).next()
|
||||||
if isinstance(r, language.http.Request):
|
if isinstance(r, language.http.Request):
|
||||||
if r.ws:
|
if r.ws:
|
||||||
return self.websocket_start(r, self.websocket_get_frame)
|
return self.websocket_start(r)
|
||||||
else:
|
else:
|
||||||
return self.http(r)
|
return self.http(r)
|
||||||
elif isinstance(r, language.websockets.WebsocketFrame):
|
elif isinstance(r, language.websockets.WebsocketFrame):
|
||||||
|
@ -185,6 +185,24 @@ class TestDaemon(_TestDaemon):
|
|||||||
def test_conn_err(self):
|
def test_conn_err(self):
|
||||||
assert "Invalid server response" in self.tval(["get:'/p/200:d2'"])
|
assert "Invalid server response" in self.tval(["get:'/p/200:d2'"])
|
||||||
|
|
||||||
|
def test_websocket_shutdown(self):
|
||||||
|
c = pathoc.Pathoc(("127.0.0.1", self.d.port), fp=None)
|
||||||
|
c.connect()
|
||||||
|
c.request("ws:/")
|
||||||
|
c.stop()
|
||||||
|
|
||||||
|
def test_wait_finish(self):
|
||||||
|
c = pathoc.Pathoc(
|
||||||
|
("127.0.0.1", self.d.port),
|
||||||
|
fp=None,
|
||||||
|
ws_read_limit = 1
|
||||||
|
)
|
||||||
|
c.connect()
|
||||||
|
c.request("ws:/")
|
||||||
|
c.request("wf:f'wf:x100'")
|
||||||
|
[i for i in c.wait(timeout=0, finish=False)]
|
||||||
|
[i for i in c.wait(timeout=0)]
|
||||||
|
|
||||||
def test_connect_fail(self):
|
def test_connect_fail(self):
|
||||||
to = ("foobar", 80)
|
to = ("foobar", 80)
|
||||||
c = pathoc.Pathoc(("127.0.0.1", self.d.port), fp=None)
|
c = pathoc.Pathoc(("127.0.0.1", self.d.port), fp=None)
|
||||||
|
Loading…
Reference in New Issue
Block a user