本文整理汇总了Python中libmproxy.models.HTTPRequest.wrap方法的典型用法代码示例。如果您正苦于以下问题:Python HTTPRequest.wrap方法的具体用法?Python HTTPRequest.wrap怎么用?Python HTTPRequest.wrap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类libmproxy.models.HTTPRequest
的用法示例。
在下文中一共展示了HTTPRequest.wrap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_decodeencode
# 需要导入模块: from libmproxy.models import HTTPRequest [as 别名]
# 或者: from libmproxy.models.HTTPRequest import wrap [as 别名]
def test_decodeencode(self):
r = HTTPRequest.wrap(netlib.tutils.treq())
r.headers["content-encoding"] = "identity"
r.content = "falafel"
r.decode()
assert "content-encoding" not in r.headers
assert r.content == "falafel"
r = HTTPRequest.wrap(netlib.tutils.treq())
r.content = "falafel"
assert not r.decode()
r = HTTPRequest.wrap(netlib.tutils.treq())
r.headers["content-encoding"] = "identity"
r.content = "falafel"
r.encode("identity")
assert r.headers["content-encoding"] == "identity"
assert r.content == "falafel"
r = HTTPRequest.wrap(netlib.tutils.treq())
r.headers["content-encoding"] = "identity"
r.content = "falafel"
r.encode("gzip")
assert r.headers["content-encoding"] == "gzip"
assert r.content != "falafel"
r.decode()
assert "content-encoding" not in r.headers
assert r.content == "falafel"
示例2: tflow
# 需要导入模块: from libmproxy.models import HTTPRequest [as 别名]
# 或者: from libmproxy.models.HTTPRequest 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
示例3: test_anticache
# 需要导入模块: from libmproxy.models import HTTPRequest [as 别名]
# 或者: from libmproxy.models.HTTPRequest import wrap [as 别名]
def test_anticache(self):
r = HTTPRequest.wrap(netlib.tutils.treq())
r.headers = Headers()
r.headers["if-modified-since"] = "test"
r.headers["if-none-match"] = "test"
r.anticache()
assert not "if-modified-since" in r.headers
assert not "if-none-match" in r.headers
示例4: test_app_registry
# 需要导入模块: from libmproxy.models import HTTPRequest [as 别名]
# 或者: from libmproxy.models.HTTPRequest import wrap [as 别名]
def test_app_registry():
ar = flow.AppRegistry()
ar.add("foo", "domain", 80)
r = HTTPRequest.wrap(netlib.tutils.treq())
r.host = "domain"
r.port = 80
assert ar.get(r)
r.port = 81
assert not ar.get(r)
r = HTTPRequest.wrap(netlib.tutils.treq())
r.host = "domain2"
r.port = 80
assert not ar.get(r)
r.headers["host"] = "domain"
assert ar.get(r)
示例5: test_get_decoded_content
# 需要导入模块: from libmproxy.models import HTTPRequest [as 别名]
# 或者: from libmproxy.models.HTTPRequest import wrap [as 别名]
def test_get_decoded_content(self):
r = HTTPRequest.wrap(netlib.tutils.treq())
r.content = None
r.headers["content-encoding"] = "identity"
assert r.get_decoded_content() is None
r.content = "falafel"
r.encode("gzip")
assert r.get_decoded_content() == "falafel"
示例6: test_constrain_encoding
# 需要导入模块: from libmproxy.models import HTTPRequest [as 别名]
# 或者: from libmproxy.models.HTTPRequest import wrap [as 别名]
def test_constrain_encoding(self):
r = HTTPRequest.wrap(netlib.tutils.treq())
r.headers["accept-encoding"] = "gzip, oink"
r.constrain_encoding()
assert "oink" not in r.headers["accept-encoding"]
r.headers.set_all("accept-encoding", ["gzip", "oink"])
r.constrain_encoding()
assert "oink" not in r.headers["accept-encoding"]
示例7: test_replace
# 需要导入模块: from libmproxy.models import HTTPRequest [as 别名]
# 或者: from libmproxy.models.HTTPRequest import wrap [as 别名]
def test_replace(self):
r = HTTPRequest.wrap(netlib.tutils.treq())
r.path = "path/foo"
r.headers["Foo"] = "fOo"
r.content = "afoob"
assert r.replace("foo(?i)", "boo") == 4
assert r.path == "path/boo"
assert not "foo" in r.content
assert r.headers["boo"] == "boo"
示例8: test_anticache
# 需要导入模块: from libmproxy.models import HTTPRequest [as 别名]
# 或者: from libmproxy.models.HTTPRequest import wrap [as 别名]
def test_anticache(self):
h = odict.ODictCaseless()
r = HTTPRequest.wrap(netlib.tutils.treq())
r.headers = h
h["if-modified-since"] = ["test"]
h["if-none-match"] = ["test"]
r.anticache()
assert not "if-modified-since" in r.headers
assert not "if-none-match" in r.headers
示例9: test_getset_form_urlencoded
# 需要导入模块: from libmproxy.models import HTTPRequest [as 别名]
# 或者: from libmproxy.models.HTTPRequest import wrap [as 别名]
def test_getset_form_urlencoded(self):
d = odict.ODict([("one", "two"), ("three", "four")])
r = HTTPRequest.wrap(netlib.tutils.treq(body=netlib.utils.urlencode(d.lst)))
r.headers["content-type"] = HDR_FORM_URLENCODED
assert r.get_form_urlencoded() == d
d = odict.ODict([("x", "y")])
r.set_form_urlencoded(d)
assert r.get_form_urlencoded() == d
r.headers["content-type"] = "foo"
assert not r.get_form_urlencoded()
示例10: test_getset_form_urlencoded
# 需要导入模块: from libmproxy.models import HTTPRequest [as 别名]
# 或者: from libmproxy.models.HTTPRequest import wrap [as 别名]
def test_getset_form_urlencoded(self):
d = odict.ODict([("one", "two"), ("three", "four")])
r = HTTPRequest.wrap(netlib.tutils.treq(content=netlib.utils.urlencode(d.lst)))
r.headers["content-type"] = "application/x-www-form-urlencoded"
assert r.get_form_urlencoded() == d
d = odict.ODict([("x", "y")])
r.set_form_urlencoded(d)
assert r.get_form_urlencoded() == d
r.headers["content-type"] = "foo"
assert not r.get_form_urlencoded()
示例11: test_path_components
# 需要导入模块: from libmproxy.models import HTTPRequest [as 别名]
# 或者: from libmproxy.models.HTTPRequest import wrap [as 别名]
def test_path_components(self):
r = HTTPRequest.wrap(netlib.tutils.treq())
r.path = "/"
assert r.get_path_components() == []
r.path = "/foo/bar"
assert r.get_path_components() == ["foo", "bar"]
q = odict.ODict()
q["test"] = ["123"]
r.set_query(q)
assert r.get_path_components() == ["foo", "bar"]
r.set_path_components([])
assert r.get_path_components() == []
r.set_path_components(["foo"])
assert r.get_path_components() == ["foo"]
r.set_path_components(["/oo"])
assert r.get_path_components() == ["/oo"]
assert "%2F" in r.path
示例12: test_decoded
# 需要导入模块: from libmproxy.models import HTTPRequest [as 别名]
# 或者: from libmproxy.models.HTTPRequest import wrap [as 别名]
def test_decoded():
r = HTTPRequest.wrap(netlib.tutils.treq())
assert r.content == "content"
assert "content-encoding" not in r.headers
r.encode("gzip")
assert r.headers["content-encoding"]
assert r.content != "content"
with decoded(r):
assert "content-encoding" not in r.headers
assert r.content == "content"
assert r.headers["content-encoding"]
assert r.content != "content"
with decoded(r):
r.content = "foo"
assert r.content != "foo"
r.decode()
assert r.content == "foo"
示例13: test_get_url
# 需要导入模块: from libmproxy.models import HTTPRequest [as 别名]
# 或者: from libmproxy.models.HTTPRequest import wrap [as 别名]
def test_get_url(self):
r = HTTPRequest.wrap(netlib.tutils.treq())
assert r.url == "http://address:22/path"
r.scheme = "https"
assert r.url == "https://address:22/path"
r.host = "host"
r.port = 42
assert r.url == "https://host:42/path"
r.host = "address"
r.port = 22
assert r.url == "https://address:22/path"
assert r.pretty_url == "https://address:22/path"
r.headers["Host"] = "foo.com"
assert r.url == "https://address:22/path"
assert r.pretty_url == "https://foo.com:22/path"
示例14: test_getset_query
# 需要导入模块: from libmproxy.models import HTTPRequest [as 别名]
# 或者: from libmproxy.models.HTTPRequest import wrap [as 别名]
def test_getset_query(self):
r = HTTPRequest.wrap(netlib.tutils.treq())
r.path = "/foo?x=y&a=b"
q = r.get_query()
assert q.lst == [("x", "y"), ("a", "b")]
r.path = "/"
q = r.get_query()
assert not q
r.path = "/?adsfa"
q = r.get_query()
assert q.lst == [("adsfa", "")]
r.path = "/foo?x=y&a=b"
assert r.get_query()
r.set_query(odict.ODict([]))
assert not r.get_query()
qv = odict.ODict([("a", "b"), ("c", "d")])
r.set_query(qv)
assert r.get_query() == qv
示例15: test_all
# 需要导入模块: from libmproxy.models import HTTPRequest [as 别名]
# 或者: from libmproxy.models.HTTPRequest 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()