Пример #1
0
 def test_repr(self):
     f = PushPromiseFrame(1)
     assert repr(f).endswith("promised_stream_id=0, data=None")
     f.promised_stream_id = 4
     f.data = b"testdata"
     assert repr(f).endswith(
         "promised_stream_id=4, data=<hex:7465737464617461>")
Пример #2
0
    def test_push_promise_frame_with_no_length_parses(self):
        # Fixes issue with empty data frames raising InvalidPaddingError.
        f = PushPromiseFrame(1)
        f.data = b''
        data = f.serialize()

        new_frame = decode_frame(data)
        assert new_frame.data == b''
Пример #3
0
    def test_push_promise_frame_invalid(self):
        data = PushPromiseFrame(1, 0).serialize()
        with pytest.raises(InvalidDataError):
            decode_frame(data)

        data = PushPromiseFrame(1, 3).serialize()
        with pytest.raises(InvalidDataError):
            decode_frame(data)
Пример #4
0
 def add_push_frame(self, stream_id, promised_stream_id, headers,
                    end_block=True):
     frame = PushPromiseFrame(stream_id)
     frame.promised_stream_id = promised_stream_id
     frame.data = self.encoder.encode(headers)
     if end_block:
         frame.flags.add('END_HEADERS')
     self.frames.append(frame)
Пример #5
0
 def add_push_frame(self, stream_id, promised_stream_id, headers,
                    end_block=True):
     frame = PushPromiseFrame(stream_id)
     frame.promised_stream_id = promised_stream_id
     frame.data = self.encoder.encode(headers)
     if end_block:
         frame.flags.add('END_HEADERS')
     self.frames.append(frame)
Пример #6
0
    def test_push_promise_frame_with_no_length_parses(self):
        # Fixes issue with empty data frames raising InvalidPaddingError.
        f = PushPromiseFrame(1)
        f.data = b''
        data = f.serialize()

        new_frame = decode_frame(data)
        assert new_frame.data == b''
Пример #7
0
    def test_push_promise_frame_serializes_properly(self):
        f = PushPromiseFrame(1)
        f.flags = set(['END_HEADERS'])
        f.promised_stream_id = 4
        f.data = b'hello world'

        s = f.serialize()
        assert s == (
            b'\x00\x00\x0F\x05\x04\x00\x00\x00\x01' +
            b'\x00\x00\x00\x04' +
            b'hello world'
        )
Пример #8
0
 def build_push_promise_frame(self,
                              stream_id,
                              promised_stream_id,
                              headers,
                              flags=[]):
     """
     Builds a single PUSH_PROMISE frame.
     """
     f = PushPromiseFrame(stream_id)
     f.promised_stream_id = promised_stream_id
     f.data = self.encoder.encode(headers)
     f.flags = set(flags)
     return f
Пример #9
0
 def build_push_promise_frame(self,
                              stream_id,
                              promised_stream_id,
                              headers,
                              flags=[]):
     """
     Builds a single PUSH_PROMISE frame.
     """
     f = PushPromiseFrame(stream_id)
     f.promised_stream_id = promised_stream_id
     f.data = self.encoder.encode(headers)
     f.flags = set(flags)
     return f
Пример #10
0
    def push_stream_in_band(self, related_stream_id, headers, encoder):
        """
        Returns a list of PUSH_PROMISE/CONTINUATION frames to emit as a pushed
        stream header. Called on the stream that has the PUSH_PROMISE frame
        sent on it.
        """
        # Because encoding headers makes an irreversible change to the header
        # compression context, we make the state transition *first*.
        events = self.state_machine.process_input(StreamInputs.SEND_PUSH_PROMISE)
        ppf = PushPromiseFrame(self.stream_id)
        ppf.promised_stream_id = related_stream_id
        frames = self._build_headers_frames(headers, encoder, ppf)

        return frames, events
Пример #11
0
    def push_stream_in_band(self, related_stream_id, headers, encoder):
        """
        Returns a list of PUSH_PROMISE/CONTINUATION frames to emit as a pushed
        stream header. Called on the stream that has the PUSH_PROMISE frame
        sent on it.
        """
        # Because encoding headers makes an irreversible change to the header
        # compression context, we make the state transition *first*.
        events = self.state_machine.process_input(
            StreamInputs.SEND_PUSH_PROMISE)
        ppf = PushPromiseFrame(self.stream_id)
        ppf.promised_stream_id = related_stream_id
        frames = self._build_headers_frames(headers, encoder, ppf)

        return frames, events
Пример #12
0
    def test_push_promise_frame_serializes_properly(self):
        f = PushPromiseFrame(1)
        f.flags = set(['END_HEADERS'])
        f.promised_stream_id = 4
        f.data = b'hello world'

        s = f.serialize()
        assert s == (b'\x00\x00\x0F\x05\x04\x00\x00\x00\x01' +
                     b'\x00\x00\x00\x04' + b'hello world')
Пример #13
0
    def test_push_promise_frame_flags(self):
        f = PushPromiseFrame(1)
        flags = f.parse_flags(0xFF)

        assert flags == set(['END_HEADERS', 'PADDED'])
Пример #14
0
    def test_push_promise_frame_flags(self):
        f = PushPromiseFrame(1)
        flags = f.parse_flags(0xFF)

        assert flags == set(['END_HEADERS', 'PADDED'])