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


Python models.HTTPResponse类代码示例

本文整理汇总了Python中libmproxy.models.HTTPResponse的典型用法代码示例。如果您正苦于以下问题:Python HTTPResponse类的具体用法?Python HTTPResponse怎么用?Python HTTPResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_decodeencode

    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"
开发者ID:keithsun80,项目名称:mitmproxy,代码行数:28,代码来源:test_flow.py

示例2: test_flow

    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
开发者ID:tracyhatemice,项目名称:mitmproxy,代码行数:29,代码来源:test_flow.py

示例3: test_set_limit

    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("~")
开发者ID:tracyhatemice,项目名称:mitmproxy,代码行数:27,代码来源:test_flow.py

示例4: test_replace

 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"
开发者ID:tracyhatemice,项目名称:mitmproxy,代码行数:7,代码来源:test_flow.py

示例5: test_server_playback

    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
开发者ID:tracyhatemice,项目名称:mitmproxy,代码行数:30,代码来源:test_flow.py

示例6: tflow

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
开发者ID:tracyhatemice,项目名称:mitmproxy,代码行数:31,代码来源:tutils.py

示例7: test_refresh_cookie

    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)
开发者ID:keithsun80,项目名称:mitmproxy,代码行数:9,代码来源:test_flow.py

示例8: test_backup

 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"
开发者ID:tracyhatemice,项目名称:mitmproxy,代码行数:10,代码来源:test_flow.py

示例9: test_missing_content

 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()
开发者ID:keithsun80,项目名称:mitmproxy,代码行数:11,代码来源:test_dump.py

示例10: _cycle

 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
开发者ID:keithsun80,项目名称:mitmproxy,代码行数:12,代码来源:test_dump.py

示例11: test_strfuncs

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)
开发者ID:camerony,项目名称:mitmproxy,代码行数:12,代码来源:test_dump.py

示例12: test_server_playback_kill

    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
开发者ID:tracyhatemice,项目名称:mitmproxy,代码行数:14,代码来源:test_flow.py

示例13: test_refresh_cookie

    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)
开发者ID:tracyhatemice,项目名称:mitmproxy,代码行数:14,代码来源:test_flow.py

示例14: test_refresh

    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()
开发者ID:keithsun80,项目名称:mitmproxy,代码行数:16,代码来源:test_flow.py

示例15: test_all

    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()
开发者ID:tracyhatemice,项目名称:mitmproxy,代码行数:24,代码来源:test_flow.py


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