Exemplo n.º 1
0
    def test_windowupdate_frames_update_windows(self):
        s = Stream(1, None, None, None, None)
        f = WindowUpdateFrame(1)
        f.window_increment = 1000
        s.receive_frame(f)

        assert s._out_flow_control_window == 65535 + 1000
Exemplo n.º 2
0
    def test_windowupdate_frames_update_windows(self):
        s = Stream(1, None, None, None, None)
        f = WindowUpdateFrame(1)
        f.window_increment = 1000
        s.receive_frame(f)

        assert s._out_flow_control_window == 65535 + 1000
Exemplo n.º 3
0
    def test_receive_unexpected_frame(self):
        # SETTINGS frames are never defined on streams, so send one of those.
        s = Stream(1, None, None, None, None, None, None)
        f = SettingsFrame(0)

        with pytest.raises(ValueError):
            s.receive_frame(f)
Exemplo n.º 4
0
    def test_can_receive_trailers(self):
        headers = [('a', 'b'), ('c', 'd'), (':status', '200')]
        trailers = [('e', 'f'), ('g', 'h')]

        s = Stream(1, None, None, None, None, FixedDecoder(headers), None)
        s.state = STATE_HALF_CLOSED_LOCAL

        # Provide the first HEADERS frame.
        f = HeadersFrame(1)
        f.data = b'hi there!'
        f.flags.add('END_HEADERS')
        s.receive_frame(f)

        assert s.response_headers == HTTPHeaderMap(headers)

        # Now, replace the dummy decoder to ensure we get a new header block.
        s._decoder = FixedDecoder(trailers)

        # Provide the trailers.
        f = HeadersFrame(1)
        f.data = b'hi there again!'
        f.flags.add('END_STREAM')
        f.flags.add('END_HEADERS')
        s.receive_frame(f)

        # Now, check the trailers.
        assert s.response_trailers == HTTPHeaderMap(trailers)

        # Confirm we closed the stream.
        assert s.state == STATE_CLOSED
Exemplo n.º 5
0
    def test_can_receive_trailers(self):
        headers = [('a', 'b'), ('c', 'd'), (':status', '200')]
        trailers = [('e', 'f'), ('g', 'h')]

        s = Stream(1, None, None, None, None, FixedDecoder(headers), None)
        s.state = STATE_HALF_CLOSED_LOCAL

        # Provide the first HEADERS frame.
        f = HeadersFrame(1)
        f.data = b'hi there!'
        f.flags.add('END_HEADERS')
        s.receive_frame(f)

        assert s.response_headers == HTTPHeaderMap(headers)

        # Now, replace the dummy decoder to ensure we get a new header block.
        s._decoder = FixedDecoder(trailers)

        # Provide the trailers.
        f = HeadersFrame(1)
        f.data = b'hi there again!'
        f.flags.add('END_STREAM')
        f.flags.add('END_HEADERS')
        s.receive_frame(f)

        # Now, check the trailers.
        assert s.response_trailers == HTTPHeaderMap(trailers)

        # Confirm we closed the stream.
        assert s.state == STATE_CLOSED
Exemplo n.º 6
0
    def test_receive_unexpected_frame(self):
        # SETTINGS frames are never defined on streams, so send one of those.
        s = Stream(1, None, None, None, None, None, None)
        f = SettingsFrame(0)

        with pytest.raises(ValueError):
            s.receive_frame(f)
Exemplo n.º 7
0
    def test_can_receive_continuation_frame_after_end_stream(self):
        s = Stream(1, None, None, None, None, None, FlowControlManager(65535))
        f = HeadersFrame(1)
        f.data = 'hi there'
        f.flags = set('END_STREAM')
        f2 = ContinuationFrame(1)
        f2.data = ' sir'
        f2.flags = set('END_HEADERS')

        s.receive_frame(f)
        s.receive_frame(f2)
Exemplo n.º 8
0
    def test_can_receive_continuation_frame_after_end_stream(self):
        s = Stream(1, None, None, None, None, None, FlowControlManager(65535))
        f = HeadersFrame(1)
        f.data = 'hi there'
        f.flags = set('END_STREAM')
        f2 = ContinuationFrame(1)
        f2.data = ' sir'
        f2.flags = set('END_HEADERS')

        s.receive_frame(f)
        s.receive_frame(f2)
Exemplo n.º 9
0
    def test_blocked_frames_cause_window_updates(self):
        out_frames = []

        def send_cb(frame, *args):
            out_frames.append(frame)

        start_window = 65535
        s = Stream(1, send_cb, None, None, None, None, FlowControlManager(start_window))
        s._data_cb = send_cb
        s.state = STATE_HALF_CLOSED_LOCAL

        # Change the window size.
        s._in_window_manager.window_size = 60000

        # Provide a BLOCKED frame.
        f = BlockedFrame(1)
        s.receive_frame(f)

        assert len(out_frames) == 1
        assert out_frames[0].type == WindowUpdateFrame.type
        assert out_frames[0].window_increment == 5535
Exemplo n.º 10
0
    def test_cannot_receive_three_header_blocks(self):
        first = [('a', 'b'), ('c', 'd'), (':status', '200')]

        s = Stream(1, None, None, None, None, FixedDecoder(first), None)
        s.state = STATE_HALF_CLOSED_LOCAL

        # Provide the first two header frames.
        f = HeadersFrame(1)
        f.data = b'hi there!'
        f.flags.add('END_HEADERS')
        s.receive_frame(f)

        f = HeadersFrame(1)
        f.data = b'hi there again!'
        f.flags.add('END_HEADERS')
        s.receive_frame(f)

        # Provide the third. This one blows up.
        f = HeadersFrame(1)
        f.data = b'hi there again!'
        f.flags.add('END_STREAM')
        f.flags.add('END_HEADERS')

        with pytest.raises(ProtocolError):
            s.receive_frame(f)
Exemplo n.º 11
0
    def test_cannot_receive_three_header_blocks(self):
        first = [('a', 'b'), ('c', 'd'), (':status', '200')]

        s = Stream(1, None, None, None, None, FixedDecoder(first), None)
        s.state = STATE_HALF_CLOSED_LOCAL

        # Provide the first two header frames.
        f = HeadersFrame(1)
        f.data = b'hi there!'
        f.flags.add('END_HEADERS')
        s.receive_frame(f)

        f = HeadersFrame(1)
        f.data = b'hi there again!'
        f.flags.add('END_HEADERS')
        s.receive_frame(f)

        # Provide the third. This one blows up.
        f = HeadersFrame(1)
        f.data = b'hi there again!'
        f.flags.add('END_STREAM')
        f.flags.add('END_HEADERS')

        with pytest.raises(ProtocolError):
            s.receive_frame(f)
Exemplo n.º 12
0
    def test_blocked_frames_cause_window_updates(self):
        out_frames = []

        def send_cb(frame, *args):
            out_frames.append(frame)

        start_window = 65535
        s = Stream(1, send_cb, None, None, None, None,
                   FlowControlManager(start_window))
        s._data_cb = send_cb
        s.state = STATE_HALF_CLOSED_LOCAL

        # Change the window size.
        s._in_window_manager.window_size = 60000

        # Provide a BLOCKED frame.
        f = BlockedFrame(1)
        s.receive_frame(f)

        assert len(out_frames) == 1
        assert out_frames[0].type == WindowUpdateFrame.type
        assert out_frames[0].window_increment == 5535
Exemplo n.º 13
0
 def test_receiving_a_frame_queues_it(self):
     s = Stream(1, None, None, None, None)
     s.receive_frame(Frame(0))
     assert len(s._queued_frames) == 1
Exemplo n.º 14
0
 def test_receiving_a_frame_queues_it(self):
     s = Stream(1, None, None, None, None)
     s.receive_frame(Frame(0))
     assert len(s._queued_frames) == 1