How to use the hyperframe.frame.DataFrame function in hyperframe

To help you get started, we’ve selected a few hyperframe examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github python-hyper / hyper / test / test_integration.py View on Github external
data.append(sock.recv(65535))
            req_event.wait(5)

            h = HeadersFrame(1)
            h.data = self.get_encoder().encode(
                [
                    (':status', 200),
                    ('content-type', 'not/real'),
                    ('content-length', 12),
                    ('server', 'socket-level-server')
                ]
            )
            h.flags.add('END_HEADERS')
            sock.send(h.serialize())

            d = DataFrame(1)
            d.data = b'thisisaproxy'
            d.flags.add('END_STREAM')
            sock.send(d.serialize())

            recv_event.wait(5)
            sock.close()
github python-hyper / hyper-h2 / test / test_basic_logic.py View on Github external
def sanity_check_data_frame(data_frame,
                            expected_flow_controlled_length,
                            expect_padded_flag,
                            expected_data_frame_pad_length):
    """
    ``data_frame`` is a frame of type ``hyperframe.frame.DataFrame``,
    and the ``flags`` and ``flow_controlled_length`` of ``data_frame``
    match expectations.
    """

    assert isinstance(data_frame, hyperframe.frame.DataFrame)

    assert data_frame.flow_controlled_length == expected_flow_controlled_length

    if expect_padded_flag:
        assert 'PADDED' in data_frame.flags
    else:
        assert 'PADDED' not in data_frame.flags

    assert data_frame.pad_length == expected_data_frame_pad_length
github richtier / alexa-voice-service-client / tests / alexa_client / helpers.py View on Github external
def create_socket(status_code, data, headers):
        # test helper method
        encoder = Encoder()
        h1 = HeadersFrame(1)
        h1.data = encoder.encode(
            [(':status', status_code), ('content-length', len(data))] + headers
        )
        h1.flags |= set(['END_HEADERS'])

        d1 = DataFrame(1)
        d1.data = data

        d2 = DataFrame(1)
        d2.flags |= set(['END_STREAM'])

        content = b''.join(f.serialize() for f in [h1, d1, d2])
        buffer = BytesIO(content)

        return DummySocket(buffer)
github python-hyper / hyperframe / test / test_frames.py View on Github external
def test_body_length_behaves_correctly(self):
        f = DataFrame(1)

        f.data = b'\x01' * 300

        # Initially the body length is zero. For now this is incidental, but
        # I'm going to test it to ensure that the behaviour is codified. We
        # should change this test if we change that.
        assert f.body_len == 0

        f.serialize()
        assert f.body_len == 300
github web-platform-tests / wpt / tools / third_party / h2 / h2 / stream.py View on Github external
def end_stream(self):
        """
        End a stream without sending data.
        """
        self.config.logger.debug("End stream %r", self)

        self.state_machine.process_input(StreamInputs.SEND_END_STREAM)
        df = DataFrame(self.stream_id)
        df.flags.add('END_STREAM')
        return [df]
github python-hyper / hyperframe / test / test_frames.py View on Github external
def test_data_frame_serializes_properly(self, data):
        f = DataFrame(1)
        f.flags = set(['END_STREAM'])
        f.data = data

        s = f.serialize()
        assert s == self.payload
github python-hyper / hyperframe / test / test_frames.py View on Github external
def test_data_frame_zero_length_padding_calculates_flow_control_len(self):
        f = DataFrame(1)
        f.flags = set(['PADDED'])
        f.data = b'testdata'
        f.pad_length = 0

        assert f.flow_controlled_length == len(b'testdata') + 1
github mitmproxy / mitmproxy / netlib / http / http2 / connections.py View on Github external
def _create_body(self, body, stream_id):
        if body is None or len(body) == 0:
            return b''

        chunk_size = self.http2_settings[hyperframe.frame.SettingsFrame.MAX_FRAME_SIZE]
        chunks = range(0, len(body), chunk_size)
        frms = [hyperframe.frame.DataFrame(
            flags=[],
            stream_id=stream_id,
            data=body[i:i + chunk_size]) for i in chunks]
        frms[-1].flags.add('END_STREAM')

        if self.dump_frames:  # pragma no cover
            for frm in frms:
                print(frm.human_readable(">>"))

        return [frm.serialize() for frm in frms]
github mitmproxy / mitmproxy / pathod / protocols / http2.py View on Github external
def _create_body(self, body, stream_id):
        if body is None or len(body) == 0:
            return b''

        chunk_size = self.http2_settings[hyperframe.frame.SettingsFrame.MAX_FRAME_SIZE]
        chunks = range(0, len(body), chunk_size)
        frms = [hyperframe.frame.DataFrame(
            flags=[],
            stream_id=stream_id,
            data=body[i:i + chunk_size]) for i in chunks]
        frms[-1].flags.add('END_STREAM')

        if self.dump_frames:  # pragma: no cover
            for frm in frms:
                print(">> ", repr(frm))

        return [frm.serialize() for frm in frms]