当前位置: 首页>>代码示例>>Python>>正文


Python HTTPRequest.wrap方法代码示例

本文整理汇总了Python中mitmproxy.models.HTTPRequest.wrap方法的典型用法代码示例。如果您正苦于以下问题:Python HTTPRequest.wrap方法的具体用法?Python HTTPRequest.wrap怎么用?Python HTTPRequest.wrap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mitmproxy.models.HTTPRequest的用法示例。


在下文中一共展示了HTTPRequest.wrap方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: tflow

# 需要导入模块: from mitmproxy.models import HTTPRequest [as 别名]
# 或者: from mitmproxy.models.HTTPRequest import wrap [as 别名]
def tflow(client_conn=True, server_conn=True, req=True, resp=None, err=None):
    """
    @type client_conn: bool | None | mitmproxy.proxy.connection.ClientConnection
    @type server_conn: bool | None | mitmproxy.proxy.connection.ServerConnection
    @type req:         bool | None | mitmproxy.protocol.http.HTTPRequest
    @type resp:        bool | None | mitmproxy.protocol.http.HTTPResponse
    @type err:         bool | None | mitmproxy.protocol.primitives.Error
    @return:           mitmproxy.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
开发者ID:Amerge,项目名称:mitmproxy,代码行数:33,代码来源:tutils.py

示例2: test_anticache

# 需要导入模块: from mitmproxy.models import HTTPRequest [as 别名]
# 或者: from mitmproxy.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
开发者ID:Amerge,项目名称:mitmproxy,代码行数:10,代码来源:test_flow.py

示例3: test_constrain_encoding

# 需要导入模块: from mitmproxy.models import HTTPRequest [as 别名]
# 或者: from mitmproxy.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"]
开发者ID:mkagenius,项目名称:mitmproxy,代码行数:11,代码来源:test_flow.py

示例4: test_replace

# 需要导入模块: from mitmproxy.models import HTTPRequest [as 别名]
# 或者: from mitmproxy.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 = b"afoob"
     assert r.replace("foo(?i)", "boo") == 4
     assert r.path == "path/boo"
     assert b"foo" not in r.content
     assert r.headers["boo"] == "boo"
开发者ID:mkagenius,项目名称:mitmproxy,代码行数:11,代码来源:test_flow.py

示例5: test_app_registry

# 需要导入模块: from mitmproxy.models import HTTPRequest [as 别名]
# 或者: from mitmproxy.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)
开发者ID:mkagenius,项目名称:mitmproxy,代码行数:20,代码来源:test_flow.py

示例6: test_get_decoded_content

# 需要导入模块: from mitmproxy.models import HTTPRequest [as 别名]
# 或者: from mitmproxy.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"
开发者ID:Amerge,项目名称:mitmproxy,代码行数:11,代码来源:test_flow.py

示例7: test_getset_form_urlencoded

# 需要导入模块: from mitmproxy.models import HTTPRequest [as 别名]
# 或者: from mitmproxy.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()
开发者ID:jqt3of5,项目名称:mitmproxy,代码行数:14,代码来源:test_flow.py

示例8: test_path_components

# 需要导入模块: from mitmproxy.models import HTTPRequest [as 别名]
# 或者: from mitmproxy.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
开发者ID:jqt3of5,项目名称:mitmproxy,代码行数:20,代码来源:test_flow.py

示例9: test_all

# 需要导入模块: from mitmproxy.models import HTTPRequest [as 别名]
# 或者: from mitmproxy.models.HTTPRequest import wrap [as 别名]
    def test_all(self):
        s = flow.State()
        fm = flow.FlowMaster(None, None, s)
        f = tutils.tflow(req=None)
        fm.clientconnect(f.client_conn)
        f.request = HTTPRequest.wrap(netlib.tutils.treq())
        fm.request(f)
        assert s.flow_count() == 1

        f.response = HTTPResponse.wrap(netlib.tutils.tresp())
        fm.response(f)
        assert s.flow_count() == 1

        fm.clientdisconnect(f.client_conn)

        f.error = Error("msg")
        fm.error(f)

        fm.shutdown()
开发者ID:mkagenius,项目名称:mitmproxy,代码行数:21,代码来源:test_flow.py

示例10: test_get_url

# 需要导入模块: from mitmproxy.models import HTTPRequest [as 别名]
# 或者: from mitmproxy.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:22"
        assert r.url == "https://address:22/path"
        assert r.pretty_url == "https://foo.com:22/path"
开发者ID:mkagenius,项目名称:mitmproxy,代码行数:22,代码来源:test_flow.py

示例11: test_getset_query

# 需要导入模块: from mitmproxy.models import HTTPRequest [as 别名]
# 或者: from mitmproxy.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
开发者ID:jqt3of5,项目名称:mitmproxy,代码行数:23,代码来源:test_flow.py

示例12: test_all

# 需要导入模块: from mitmproxy.models import HTTPRequest [as 别名]
# 或者: from mitmproxy.models.HTTPRequest import wrap [as 别名]
    def test_all(self):
        s = flow.State()
        fm = flow.FlowMaster(None, None, s)
        f = tutils.tflow(req=None)
        fm.clientconnect(f.client_conn)
        f.request = HTTPRequest.wrap(netlib.tutils.treq())
        fm.request(f)
        assert s.flow_count() == 1

        f.response = HTTPResponse.wrap(netlib.tutils.tresp())
        fm.response(f)
        assert s.flow_count() == 1

        fm.clientdisconnect(f.client_conn)

        f.error = Error("msg")
        f.error.reply = controller.DummyReply()
        fm.error(f)

        fm.load_script(tutils.test_data.path("data/scripts/a.py"))
        fm.shutdown()
开发者ID:smartnetguru,项目名称:mitmproxy,代码行数:23,代码来源:test_flow.py


注:本文中的mitmproxy.models.HTTPRequest.wrap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。