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


Python framereader.http2_read_raw_frame函数代码示例

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


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

示例1: handle

        def handle(self):
            h2_conn = h2.connection.H2Connection(client_side=False, header_encoding=False)

            preamble = self.rfile.read(24)
            h2_conn.initiate_connection()
            h2_conn.receive_data(preamble)
            self.wfile.write(h2_conn.data_to_send())
            self.wfile.flush()

            if 'h2_server_settings' in self.kwargs:
                h2_conn.update_settings(self.kwargs['h2_server_settings'])
                self.wfile.write(h2_conn.data_to_send())
                self.wfile.flush()

            done = False
            while not done:
                try:
                    raw = b''.join(framereader.http2_read_raw_frame(self.rfile))
                    events = h2_conn.receive_data(raw)
                except HttpException:
                    print(traceback.format_exc())
                    assert False
                except:
                    break
                self.wfile.write(h2_conn.data_to_send())
                self.wfile.flush()

                for event in events:
                    try:
                        if not self.server.handle_server_event(event, h2_conn, self.rfile, self.wfile):
                            done = True
                            break
                    except:
                        done = True
                        break
开发者ID:laborautonomo,项目名称:mitmproxy,代码行数:35,代码来源:test_protocol_http2.py

示例2: test_connection_terminated

    def test_connection_terminated(self):
        client, h2_conn = self._setup_connection()

        self._send_request(client.wfile, h2_conn, headers=[
            (':authority', "127.0.0.1:%s" % self.server.server.address.port),
            (':method', 'GET'),
            (':scheme', 'https'),
            (':path', '/'),
        ])

        done = False
        connection_terminated_event = None
        while not done:
            try:
                raw = b''.join(framereader.http2_read_raw_frame(client.rfile))
                events = h2_conn.receive_data(raw)
                for event in events:
                    if isinstance(event, h2.events.ConnectionTerminated):
                        connection_terminated_event = event
                        done = True
            except:
                break

        assert len(self.master.state.flows) == 1
        assert connection_terminated_event is not None
        assert connection_terminated_event.error_code == 5
        assert connection_terminated_event.last_stream_id == 42
        assert connection_terminated_event.additional_data == 'foobar'
开发者ID:laborautonomo,项目名称:mitmproxy,代码行数:28,代码来源:test_protocol_http2.py

示例3: test_connection_lost

    def test_connection_lost(self):
        client, h2_conn = self._setup_connection()

        self._send_request(client.wfile, h2_conn, stream_id=1, headers=[
            (':authority', "127.0.0.1:%s" % self.server.server.address.port),
            (':method', 'GET'),
            (':scheme', 'https'),
            (':path', '/'),
            ('foo', 'bar')
        ])

        done = False
        while not done:
            try:
                raw = b''.join(framereader.http2_read_raw_frame(client.rfile))
                h2_conn.receive_data(raw)
            except HttpException:
                print(traceback.format_exc())
                assert False
            except:
                break
            try:
                client.wfile.write(h2_conn.data_to_send())
                client.wfile.flush()
            except:
                break

        if len(self.master.state.flows) == 1:
            assert self.master.state.flows[0].response is None
开发者ID:laborautonomo,项目名称:mitmproxy,代码行数:29,代码来源:test_protocol_http2.py

示例4: test_with_bodies

    def test_with_bodies(self):
        client, h2_conn = self._setup_connection()

        self._send_request(
            client.wfile,
            h2_conn,
            headers=[
                (':authority', "127.0.0.1:%s" % self.server.server.address.port),
                (':method', 'GET'),
                (':scheme', 'https'),
                (':path', '/'),
            ],
            body='foobar with request body',
        )

        done = False
        while not done:
            try:
                events = h2_conn.receive_data(b''.join(framereader.http2_read_raw_frame(client.rfile)))
            except:
                break
            client.wfile.write(h2_conn.data_to_send())
            client.wfile.flush()

            for event in events:
                if isinstance(event, h2.events.StreamEnded):
                    done = True

        h2_conn.close_connection()
        client.wfile.write(h2_conn.data_to_send())
        client.wfile.flush()

        assert self.master.state.flows[0].response.body == b'foobar with request body'
开发者ID:AlTune,项目名称:mitmproxy,代码行数:33,代码来源:test_protocol_http2.py

示例5: test_simple

    def test_simple(self):
        client, h2_conn = self._setup_connection()

        self._send_request(client.wfile, h2_conn, headers=[
            (':authority', "127.0.0.1:%s" % self.server.server.address.port),
            (':method', 'GET'),
            (':scheme', 'https'),
            (':path', '/'),
            ('ClIeNt-FoO', 'client-bar-1'),
            ('ClIeNt-FoO', 'client-bar-2'),
        ], body='my request body echoed back to me')

        done = False
        while not done:
            try:
                events = h2_conn.receive_data(b''.join(framereader.http2_read_raw_frame(client.rfile)))
            except:
                break
            client.wfile.write(h2_conn.data_to_send())
            client.wfile.flush()

            for event in events:
                if isinstance(event, h2.events.StreamEnded):
                    done = True

        h2_conn.close_connection()
        client.wfile.write(h2_conn.data_to_send())
        client.wfile.flush()

        assert len(self.master.state.flows) == 1
        assert self.master.state.flows[0].response.status_code == 200
        assert self.master.state.flows[0].response.headers['server-foo'] == 'server-bar'
        assert self.master.state.flows[0].response.headers['föo'] == 'bär'
        assert self.master.state.flows[0].response.body == b'foobar'
开发者ID:AlTune,项目名称:mitmproxy,代码行数:34,代码来源:test_protocol_http2.py

示例6: handle

        def handle(self):
            # send magic
            self.wfile.write(codecs.decode("505249202a20485454502f322e300d0a0d0a534d0d0a0d0a", "hex_codec"))
            self.wfile.flush()

            # send empty settings frame
            self.wfile.write(codecs.decode("000000040000000000", "hex_codec"))
            self.wfile.flush()

            # check empty settings frame
            raw = framereader.http2_read_raw_frame(self.rfile)
            assert raw == codecs.decode("00000c040000000000000200000000000300000001", "hex_codec")

            # check settings acknowledgement
            raw = framereader.http2_read_raw_frame(self.rfile)
            assert raw == codecs.decode("000000040100000000", "hex_codec")

            # send settings acknowledgement
            self.wfile.write(codecs.decode("000000040100000000", "hex_codec"))
            self.wfile.flush()
开发者ID:dufferzafar,项目名称:mitmproxy,代码行数:20,代码来源:test_protocols_http2.py

示例7: test_push_promise

    def test_push_promise(self):
        client, h2_conn = self._setup_connection()

        self._send_request(client.wfile, h2_conn, stream_id=1, headers=[
            (':authority', "127.0.0.1:%s" % self.server.server.address.port),
            (':method', 'GET'),
            (':scheme', 'https'),
            (':path', '/'),
            ('foo', 'bar')
        ])

        done = False
        ended_streams = 0
        pushed_streams = 0
        responses = 0
        while not done:
            try:
                raw = b''.join(framereader.http2_read_raw_frame(client.rfile))
                events = h2_conn.receive_data(raw)
            except HttpException:
                print(traceback.format_exc())
                assert False
            except:
                break
            client.wfile.write(h2_conn.data_to_send())
            client.wfile.flush()

            for event in events:
                if isinstance(event, h2.events.StreamEnded):
                    ended_streams += 1
                elif isinstance(event, h2.events.PushedStreamReceived):
                    pushed_streams += 1
                elif isinstance(event, h2.events.ResponseReceived):
                    responses += 1
                if isinstance(event, h2.events.ConnectionTerminated):
                    done = True

            if responses == 3 and ended_streams == 3 and pushed_streams == 2:
                done = True

        h2_conn.close_connection()
        client.wfile.write(h2_conn.data_to_send())
        client.wfile.flush()

        assert ended_streams == 3
        assert pushed_streams == 2

        bodies = [flow.response.body for flow in self.master.state.flows]
        assert len(bodies) == 3
        assert b'regular_stream' in bodies
        assert b'pushed_stream_foo' in bodies
        assert b'pushed_stream_bar' in bodies
开发者ID:laborautonomo,项目名称:mitmproxy,代码行数:52,代码来源:test_protocol_http2.py

示例8: test_simple

    def test_simple(self):
        response_body_buffer = b''
        client, h2_conn = self._setup_connection()

        self._send_request(
            client.wfile,
            h2_conn,
            headers=[
                (':authority', "127.0.0.1:%s" % self.server.server.address.port),
                (':method', 'GET'),
                (':scheme', 'https'),
                (':path', '/'),
                ('ClIeNt-FoO', 'client-bar-1'),
                ('ClIeNt-FoO', 'client-bar-2'),
            ],
            body=b'request body')

        done = False
        while not done:
            try:
                raw = b''.join(framereader.http2_read_raw_frame(client.rfile))
                events = h2_conn.receive_data(raw)
            except HttpException:
                print(traceback.format_exc())
                assert False

            client.wfile.write(h2_conn.data_to_send())
            client.wfile.flush()

            for event in events:
                if isinstance(event, h2.events.DataReceived):
                    response_body_buffer += event.data
                elif isinstance(event, h2.events.StreamEnded):
                    done = True

        h2_conn.close_connection()
        client.wfile.write(h2_conn.data_to_send())
        client.wfile.flush()

        assert len(self.master.state.flows) == 1
        assert self.master.state.flows[0].response.status_code == 200
        assert self.master.state.flows[0].response.headers['server-foo'] == 'server-bar'
        assert self.master.state.flows[0].response.headers['föo'] == 'bär'
        assert self.master.state.flows[0].response.body == b'response body'
        assert self.request_body_buffer == b'request body'
        assert response_body_buffer == b'response body'
开发者ID:DrakeCaraker,项目名称:mitmproxy,代码行数:46,代码来源:test_protocol_http2.py

示例9: test_push_promise_reset

    def test_push_promise_reset(self):
        client, h2_conn = self._setup_connection()

        self._send_request(client.wfile, h2_conn, stream_id=1, headers=[
            (':authority', "127.0.0.1:%s" % self.server.server.address.port),
            (':method', 'GET'),
            (':scheme', 'https'),
            (':path', '/'),
            ('foo', 'bar')
        ])

        done = False
        ended_streams = 0
        pushed_streams = 0
        responses = 0
        while not done:
            try:
                events = h2_conn.receive_data(b''.join(framereader.http2_read_raw_frame(client.rfile)))
            except:
                break
            client.wfile.write(h2_conn.data_to_send())
            client.wfile.flush()

            for event in events:
                if isinstance(event, h2.events.StreamEnded) and event.stream_id == 1:
                    ended_streams += 1
                elif isinstance(event, h2.events.PushedStreamReceived):
                    pushed_streams += 1
                    h2_conn.reset_stream(event.pushed_stream_id, error_code=0x8)
                    client.wfile.write(h2_conn.data_to_send())
                    client.wfile.flush()
                elif isinstance(event, h2.events.ResponseReceived):
                    responses += 1
                if isinstance(event, h2.events.ConnectionTerminated):
                    done = True

            if responses >= 1 and ended_streams >= 1 and pushed_streams == 2:
                done = True

        h2_conn.close_connection()
        client.wfile.write(h2_conn.data_to_send())
        client.wfile.flush()

        bodies = [flow.response.body for flow in self.master.state.flows if flow.response]
        assert len(bodies) >= 1
        assert b'regular_stream' in bodies
开发者ID:AlTune,项目名称:mitmproxy,代码行数:46,代码来源:test_protocol_http2.py

示例10: test_priority_with_existing_stream

    def test_priority_with_existing_stream(self):
        client, h2_conn = self._setup_connection()

        self._send_request(
            client.wfile,
            h2_conn,
            headers=[
                (':authority', "127.0.0.1:{}".format(self.server.server.address.port)),
                (':method', 'GET'),
                (':scheme', 'https'),
                (':path', '/'),
            ],
            end_stream=False,
        )

        h2_conn.prioritize(1, exclusive=True, depends_on=0, weight=42)
        h2_conn.end_stream(1)
        client.wfile.write(h2_conn.data_to_send())
        client.wfile.flush()

        done = False
        while not done:
            try:
                raw = b''.join(framereader.http2_read_raw_frame(client.rfile))
                events = h2_conn.receive_data(raw)
            except HttpException:
                print(traceback.format_exc())
                assert False

            client.wfile.write(h2_conn.data_to_send())
            client.wfile.flush()

            for event in events:
                if isinstance(event, h2.events.StreamEnded):
                    done = True

        h2_conn.close_connection()
        client.wfile.write(h2_conn.data_to_send())
        client.wfile.flush()

        assert len(self.master.state.flows) == 1
        assert self.priority_data == [(True, 0, 42)]
开发者ID:YanchWare,项目名称:mitmproxy,代码行数:42,代码来源:test_protocol_http2.py

示例11: test_request_with_priority

    def test_request_with_priority(self):
        client, h2_conn = self._setup_connection()

        self._send_request(
            client.wfile,
            h2_conn,
            headers=[
                (':authority', "127.0.0.1:%s" % self.server.server.address.port),
                (':method', 'GET'),
                (':scheme', 'https'),
                (':path', '/'),
            ],
            priority_exclusive = True,
            priority_depends_on = 42424242,
            priority_weight = 42,
        )

        done = False
        while not done:
            try:
                raw = b''.join(framereader.http2_read_raw_frame(client.rfile))
                events = h2_conn.receive_data(raw)
            except HttpException:
                print(traceback.format_exc())
                assert False

            client.wfile.write(h2_conn.data_to_send())
            client.wfile.flush()

            for event in events:
                if isinstance(event, h2.events.StreamEnded):
                    done = True

        h2_conn.close_connection()
        client.wfile.write(h2_conn.data_to_send())
        client.wfile.flush()

        assert len(self.master.state.flows) == 1
        assert self.master.state.flows[0].response.headers['priority_exclusive'] == 'True'
        assert self.master.state.flows[0].response.headers['priority_depends_on'] == '42424242'
        assert self.master.state.flows[0].response.headers['priority_weight'] == '42'
开发者ID:DrakeCaraker,项目名称:mitmproxy,代码行数:41,代码来源:test_protocol_http2.py

示例12: test_body_size_limit

    def test_body_size_limit(self):
        self.config.body_size_limit = 20

        client, h2_conn = self._setup_connection()

        self._send_request(
            client.wfile,
            h2_conn,
            headers=[
                (':authority', "127.0.0.1:%s" % self.server.server.address.port),
                (':method', 'GET'),
                (':scheme', 'https'),
                (':path', '/'),
            ],
            body=b'very long body over 20 characters long',
        )

        done = False
        while not done:
            try:
                raw = b''.join(framereader.http2_read_raw_frame(client.rfile))
                events = h2_conn.receive_data(raw)
            except HttpException:
                print(traceback.format_exc())
                assert False

            client.wfile.write(h2_conn.data_to_send())
            client.wfile.flush()

            for event in events:
                if isinstance(event, h2.events.StreamReset):
                    done = True

        h2_conn.close_connection()
        client.wfile.write(h2_conn.data_to_send())
        client.wfile.flush()

        assert len(self.master.state.flows) == 0
开发者ID:DrakeCaraker,项目名称:mitmproxy,代码行数:38,代码来源:test_protocol_http2.py

示例13: test_max_concurrent_streams

    def test_max_concurrent_streams(self):
        client, h2_conn = self._setup_connection()
        new_streams = [1, 3, 5, 7, 9, 11]
        for id in new_streams:
            # this will exceed MAX_CONCURRENT_STREAMS on the server connection
            # and cause mitmproxy to throttle stream creation to the server
            self._send_request(client.wfile, h2_conn, stream_id=id, headers=[
                (':authority', "127.0.0.1:%s" % self.server.server.address.port),
                (':method', 'GET'),
                (':scheme', 'https'),
                (':path', '/'),
                ('X-Stream-ID', str(id)),
            ])

        ended_streams = 0
        while ended_streams != len(new_streams):
            try:
                header, body = framereader.http2_read_raw_frame(client.rfile)
                events = h2_conn.receive_data(b''.join([header, body]))
            except:
                break
            client.wfile.write(h2_conn.data_to_send())
            client.wfile.flush()

            for event in events:
                if isinstance(event, h2.events.StreamEnded):
                    ended_streams += 1

        h2_conn.close_connection()
        client.wfile.write(h2_conn.data_to_send())
        client.wfile.flush()

        assert len(self.master.state.flows) == len(new_streams)
        for flow in self.master.state.flows:
            assert flow.response.status_code == 200
            assert "Stream-ID" in flow.response.body
开发者ID:laborautonomo,项目名称:mitmproxy,代码行数:36,代码来源:test_protocol_http2.py


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