本文整理汇总了Python中libmproxy.models.HTTPResponse.wrap方法的典型用法代码示例。如果您正苦于以下问题:Python HTTPResponse.wrap方法的具体用法?Python HTTPResponse.wrap怎么用?Python HTTPResponse.wrap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类libmproxy.models.HTTPResponse
的用法示例。
在下文中一共展示了HTTPResponse.wrap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_decodeencode
# 需要导入模块: from libmproxy.models import HTTPResponse [as 别名]
# 或者: from libmproxy.models.HTTPResponse import wrap [as 别名]
def test_decodeencode(self):
r = HTTPResponse.wrap(netlib.tutils.tresp())
r.headers["content-encoding"] = "identity"
r.content = "falafel"
assert r.decode()
assert "content-encoding" not in r.headers
assert r.content == "falafel"
r = HTTPResponse.wrap(netlib.tutils.tresp())
r.headers["content-encoding"] = "identity"
r.content = "falafel"
r.encode("identity")
assert r.headers["content-encoding"] == "identity"
assert r.content == "falafel"
r = HTTPResponse.wrap(netlib.tutils.tresp())
r.headers["content-encoding"] = "identity"
r.content = "falafel"
r.encode("gzip")
assert r.headers["content-encoding"] == "gzip"
assert r.content != "falafel"
assert r.decode()
assert "content-encoding" not in r.headers
assert r.content == "falafel"
r.headers["content-encoding"] = "gzip"
assert not r.decode()
assert r.content == "falafel"
示例2: test_flow
# 需要导入模块: from libmproxy.models import HTTPResponse [as 别名]
# 或者: from libmproxy.models.HTTPResponse import wrap [as 别名]
def test_flow(self):
"""
normal flow:
connect -> request -> response
"""
c = flow.State()
f = tutils.tflow()
c.add_flow(f)
assert f
assert c.flow_count() == 1
assert c.active_flow_count() == 1
newf = tutils.tflow()
assert c.add_flow(newf)
assert c.active_flow_count() == 2
f.response = HTTPResponse.wrap(netlib.tutils.tresp())
assert c.update_flow(f)
assert c.flow_count() == 2
assert c.active_flow_count() == 1
_ = HTTPResponse.wrap(netlib.tutils.tresp())
assert not c.update_flow(None)
assert c.active_flow_count() == 1
newf.response = HTTPResponse.wrap(netlib.tutils.tresp())
assert c.update_flow(newf)
assert c.active_flow_count() == 0
示例3: test_set_limit
# 需要导入模块: from libmproxy.models import HTTPResponse [as 别名]
# 或者: from libmproxy.models.HTTPResponse import wrap [as 别名]
def test_set_limit(self):
c = flow.State()
f = tutils.tflow()
assert len(c.view) == 0
c.add_flow(f)
assert len(c.view) == 1
c.set_limit("~s")
assert c.limit_txt == "~s"
assert len(c.view) == 0
f.response = HTTPResponse.wrap(netlib.tutils.tresp())
c.update_flow(f)
assert len(c.view) == 1
c.set_limit(None)
assert len(c.view) == 1
f = tutils.tflow()
c.add_flow(f)
assert len(c.view) == 2
c.set_limit("~q")
assert len(c.view) == 1
c.set_limit("~s")
assert len(c.view) == 1
assert "Invalid" in c.set_limit("~")
示例4: test_replace
# 需要导入模块: from libmproxy.models import HTTPResponse [as 别名]
# 或者: from libmproxy.models.HTTPResponse import wrap [as 别名]
def test_replace(self):
r = HTTPResponse.wrap(netlib.tutils.tresp())
r.headers["Foo"] = "fOo"
r.content = "afoob"
assert r.replace("foo(?i)", "boo") == 3
assert not "foo" in r.content
assert r.headers["boo"] == "boo"
示例5: test_server_playback
# 需要导入模块: from libmproxy.models import HTTPResponse [as 别名]
# 或者: from libmproxy.models.HTTPResponse import wrap [as 别名]
def test_server_playback(self):
s = flow.State()
f = tutils.tflow()
f.response = HTTPResponse.wrap(netlib.tutils.tresp(content=f.request))
pb = [f]
fm = flow.FlowMaster(None, s)
fm.refresh_server_playback = True
assert not fm.do_server_playback(tutils.tflow())
fm.start_server_playback(pb, False, [], False, False, None, False,
None, False)
assert fm.do_server_playback(tutils.tflow())
fm.start_server_playback(pb, False, [], True, False, None, False, None,
False)
r = tutils.tflow()
r.request.content = "gibble"
assert not fm.do_server_playback(r)
assert fm.do_server_playback(tutils.tflow())
fm.start_server_playback(pb, False, [], True, False, None, False, None,
False)
q = Queue.Queue()
fm.tick(q, 0)
assert fm.should_exit.is_set()
fm.stop_server_playback()
assert not fm.server_playback
示例6: tflow
# 需要导入模块: from libmproxy.models import HTTPResponse [as 别名]
# 或者: from libmproxy.models.HTTPResponse import wrap [as 别名]
def tflow(client_conn=True, server_conn=True, req=True, resp=None, err=None):
"""
@type client_conn: bool | None | libmproxy.proxy.connection.ClientConnection
@type server_conn: bool | None | libmproxy.proxy.connection.ServerConnection
@type req: bool | None | libmproxy.protocol.http.HTTPRequest
@type resp: bool | None | libmproxy.protocol.http.HTTPResponse
@type err: bool | None | libmproxy.protocol.primitives.Error
@return: bool | None | libmproxy.protocol.http.HTTPFlow
"""
if client_conn is True:
client_conn = tclient_conn()
if server_conn is True:
server_conn = tserver_conn()
if req is True:
req = netlib.tutils.treq()
if resp is True:
resp = netlib.tutils.tresp()
if err is True:
err = terr()
if req:
req = HTTPRequest.wrap(req)
if resp:
resp = HTTPResponse.wrap(resp)
f = HTTPFlow(client_conn, server_conn)
f.request = req
f.response = resp
f.error = err
f.reply = controller.DummyReply()
return f
示例7: test_refresh_cookie
# 需要导入模块: from libmproxy.models import HTTPResponse [as 别名]
# 或者: from libmproxy.models.HTTPResponse import wrap [as 别名]
def test_refresh_cookie(self):
r = HTTPResponse.wrap(netlib.tutils.tresp())
# Invalid expires format, sent to us by Reddit.
c = "rfoo=bar; Domain=reddit.com; expires=Thu, 31 Dec 2037 23:59:59 GMT; Path=/"
assert r._refresh_cookie(c, 60)
c = "MOO=BAR; Expires=Tue, 08-Mar-2011 00:20:38 GMT; Path=foo.com; Secure"
assert "00:21:38" in r._refresh_cookie(c, 60)
示例8: test_backup
# 需要导入模块: from libmproxy.models import HTTPResponse [as 别名]
# 或者: from libmproxy.models.HTTPResponse import wrap [as 别名]
def test_backup(self):
f = tutils.tflow()
f.response = HTTPResponse.wrap(netlib.tutils.tresp())
f.request.content = "foo"
assert not f.modified()
f.backup()
f.request.content = "bar"
assert f.modified()
f.revert()
assert f.request.content == "foo"
示例9: test_missing_content
# 需要导入模块: from libmproxy.models import HTTPResponse [as 别名]
# 或者: from libmproxy.models.HTTPResponse import wrap [as 别名]
def test_missing_content(self):
cs = StringIO()
o = dump.Options(flow_detail=3)
m = dump.DumpMaster(None, o, outfile=cs)
f = tutils.tflow()
f.request.content = CONTENT_MISSING
m.handle_request(f)
f.response = HTTPResponse.wrap(netlib.tutils.tresp())
f.response.content = CONTENT_MISSING
m.handle_response(f)
assert "content missing" in cs.getvalue()
示例10: _cycle
# 需要导入模块: from libmproxy.models import HTTPResponse [as 别名]
# 或者: from libmproxy.models.HTTPResponse import wrap [as 别名]
def _cycle(self, m, content):
f = tutils.tflow(req=netlib.tutils.treq(body=content))
l = Log("connect")
l.reply = mock.MagicMock()
m.handle_log(l)
m.handle_clientconnect(f.client_conn)
m.handle_serverconnect(f.server_conn)
m.handle_request(f)
f.response = HTTPResponse.wrap(netlib.tutils.tresp(body=content))
f = m.handle_response(f)
m.handle_clientdisconnect(f.client_conn)
return f
示例11: test_strfuncs
# 需要导入模块: from libmproxy.models import HTTPResponse [as 别名]
# 或者: from libmproxy.models.HTTPResponse import wrap [as 别名]
def test_strfuncs():
t = HTTPResponse.wrap(netlib.tutils.tresp())
t.is_replay = True
dump.str_response(t)
f = tutils.tflow()
f.client_conn = None
f.request.stickycookie = True
assert "stickycookie" in dump.str_request(f, False)
assert "stickycookie" in dump.str_request(f, True)
assert "replay" in dump.str_request(f, False)
assert "replay" in dump.str_request(f, True)
示例12: test_server_playback_kill
# 需要导入模块: from libmproxy.models import HTTPResponse [as 别名]
# 或者: from libmproxy.models.HTTPResponse import wrap [as 别名]
def test_server_playback_kill(self):
s = flow.State()
f = tutils.tflow()
f.response = HTTPResponse.wrap(netlib.tutils.tresp(content=f.request))
pb = [f]
fm = flow.FlowMaster(None, s)
fm.refresh_server_playback = True
fm.start_server_playback(pb, True, [], False, False, None, False, None,
False)
f = tutils.tflow()
f.request.host = "nonexistent"
fm.process_new_request(f)
assert "killed" in f.error.msg
示例13: test_refresh_cookie
# 需要导入模块: from libmproxy.models import HTTPResponse [as 别名]
# 或者: from libmproxy.models.HTTPResponse import wrap [as 别名]
def test_refresh_cookie(self):
r = HTTPResponse.wrap(netlib.tutils.tresp())
# Invalid expires format, sent to us by Reddit.
c = "rfoo=bar; Domain=reddit.com; expires=Thu, 31 Dec 2037 23:59:59 GMT; Path=/"
assert r._refresh_cookie(c, 60)
c = "MOO=BAR; Expires=Tue, 08-Mar-2011 00:20:38 GMT; Path=foo.com; Secure"
assert "00:21:38" in r._refresh_cookie(c, 60)
# https://github.com/mitmproxy/mitmproxy/issues/773
c = ">=A"
with tutils.raises(ValueError):
r._refresh_cookie(c, 60)
示例14: test_refresh
# 需要导入模块: from libmproxy.models import HTTPResponse [as 别名]
# 或者: from libmproxy.models.HTTPResponse import wrap [as 别名]
def test_refresh(self):
r = HTTPResponse.wrap(netlib.tutils.tresp())
n = time.time()
r.headers["date"] = email.utils.formatdate(n)
pre = r.headers["date"]
r.refresh(n)
assert pre == r.headers["date"]
r.refresh(n + 60)
d = email.utils.parsedate_tz(r.headers["date"])
d = email.utils.mktime_tz(d)
# Weird that this is not exact...
assert abs(60 - (d - n)) <= 1
r.headers["set-cookie"] = "MOO=BAR; Expires=Tue, 08-Mar-2011 00:20:38 GMT; Path=foo.com; Secure"
r.refresh()
示例15: test_all
# 需要导入模块: from libmproxy.models import HTTPResponse [as 别名]
# 或者: from libmproxy.models.HTTPResponse import wrap [as 别名]
def test_all(self):
s = flow.State()
fm = flow.FlowMaster(None, s)
fm.anticache = True
fm.anticomp = True
f = tutils.tflow(req=None)
fm.handle_clientconnect(f.client_conn)
f.request = HTTPRequest.wrap(netlib.tutils.treq())
fm.handle_request(f)
assert s.flow_count() == 1
f.response = HTTPResponse.wrap(netlib.tutils.tresp())
fm.handle_response(f)
assert not fm.handle_response(None)
assert s.flow_count() == 1
fm.handle_clientdisconnect(f.client_conn)
f.error = Error("msg")
f.error.reply = controller.DummyReply()
fm.handle_error(f)
fm.load_script(tutils.test_data.path("scripts/a.py"))
fm.shutdown()