Exemplo n.º 1
0
 def test_parse_length_payload_eof(self):
     out = aiohttp.FlowControlDataQueue(self.stream)
     buf = aiohttp.ParserBuffer()
     p = protocol.HttpPayloadParser(None).parse_length_payload(out, buf, 4)
     next(p)
     p.send(b'da')
     self.assertRaises(aiohttp.EofStream, p.throw, aiohttp.EofStream)
Exemplo n.º 2
0
 def test_parse_length_payload_eof(self):
     out = aiohttp.DataQueue()
     buf = aiohttp.ParserBuffer()
     p = protocol.HttpPayloadParser(None).parse_length_payload(out, buf, 4)
     next(p)
     p.send(b'da')
     self.assertRaises(errors.IncompleteRead, p.throw, aiohttp.EofStream)
Exemplo n.º 3
0
 def test_parse_chunked_payload_incomplete(self):
     out = aiohttp.FlowControlDataQueue(self.stream)
     buf = aiohttp.ParserBuffer()
     p = protocol.HttpPayloadParser(None).parse_chunked_payload(out, buf)
     next(p)
     p.send(b'4\r\ndata\r\n')
     self.assertRaises(aiohttp.EofStream, p.throw, aiohttp.EofStream)
Exemplo n.º 4
0
 def test_http_payload_parser_length_broken(self):
     msg = protocol.RawRequestMessage('GET', '/', (1, 1),
                                      [('CONTENT-LENGTH', 'qwe')], None,
                                      None)
     out = aiohttp.DataQueue()
     buf = aiohttp.ParserBuffer()
     p = protocol.HttpPayloadParser(msg)(out, buf)
     self.assertRaises(errors.InvalidHeader, next, p)
Exemplo n.º 5
0
 def test_http_payload_parser_no_length(self):
     msg = protocol.RawRequestMessage('GET', '/', (1, 1), [], None, None)
     out = aiohttp.DataQueue()
     buf = aiohttp.ParserBuffer()
     p = protocol.HttpPayloadParser(msg, readall=False)(out, buf)
     self.assertRaises(StopIteration, next, p)
     self.assertEqual(b'', b''.join(out._buffer))
     self.assertTrue(out._eof)
Exemplo n.º 6
0
 def test_http_payload_parser_length_wrong(self):
     msg = protocol.RawRequestMessage(
         'GET', '/', (1, 1), CIMultiDict([('CONTENT-LENGTH', '-1')]), None,
         None)
     out = aiohttp.FlowControlDataQueue(self.stream)
     buf = aiohttp.ParserBuffer()
     p = protocol.HttpPayloadParser(msg)(out, buf)
     self.assertRaises(errors.InvalidHeader, next, p)
Exemplo n.º 7
0
    def test_http_payload_parser_length(self):
        out = aiohttp.FlowControlDataQueue(self.stream)
        p = protocol.HttpPayloadParser(out, length=2)
        eof, tail = p.feed_data(b'1245')
        self.assertTrue(eof)

        self.assertEqual(b'12', b''.join(d for d, _ in out._buffer))
        self.assertEqual(b'45', tail)
Exemplo n.º 8
0
    def test_http_payload_parser_chunked(self):
        out = aiohttp.FlowControlDataQueue(self.stream)
        parser = protocol.HttpPayloadParser(out, chunked=True)
        assert not parser.done

        parser.feed_data(b'4;test\r\ndata\r\n4\r\nline\r\n0\r\ntest\r\n')
        self.assertEqual(b'dataline', b''.join(d for d, _ in out._buffer))
        self.assertTrue(out.is_eof())
Exemplo n.º 9
0
    def _test_parse_length_payload_eof(self):
        out = aiohttp.FlowControlDataQueue(self.stream)

        p = protocol.HttpPayloadParser(None)
        p.start(4, out)

        p.feed_data(b'da')
        p.feed_eof()
Exemplo n.º 10
0
 def test_parse_chunked_payload(self):
     out = aiohttp.FlowControlDataQueue(self.stream)
     p = protocol.HttpPayloadParser(out, chunked=True)
     eof, tail = p.feed_data(b'4\r\ndata\r\n4\r\nline\r\n0\r\ntest\r\n')
     self.assertEqual(b'dataline', b''.join(d for d, _ in out._buffer))
     self.assertEqual(b'', tail)
     self.assertTrue(eof)
     self.assertTrue(out.is_eof())
Exemplo n.º 11
0
    def test_parse_eof_payload(self):
        out = aiohttp.FlowControlDataQueue(self.stream)
        p = protocol.HttpPayloadParser(out, readall=True)
        p.feed_data(b'data')
        p.feed_eof()

        self.assertTrue(out.is_eof())
        self.assertEqual([(bytearray(b'data'), 4)], list(out._buffer))
Exemplo n.º 12
0
 def test_http_payload_parser_length_zero(self):
     msg = protocol.RawRequestMessage('GET', '/', (1, 1),
                                      [('CONTENT-LENGTH', '0')], None, None)
     out = aiohttp.DataQueue()
     buf = aiohttp.ParserBuffer()
     p = protocol.HttpPayloadParser(msg)(out, buf)
     self.assertRaises(StopIteration, next, p)
     self.assertEqual(b'', b''.join(out._buffer))
Exemplo n.º 13
0
 def test_http_payload_parser_deflate(self):
     length = len(self._COMPRESSED)
     out = aiohttp.FlowControlDataQueue(self.stream)
     p = protocol.HttpPayloadParser(out,
                                    length=length,
                                    compression='deflate')
     p.feed_data(self._COMPRESSED)
     self.assertEqual(b'data', b''.join(d for d, _ in out._buffer))
     self.assertTrue(out.is_eof())
Exemplo n.º 14
0
    def test_http_payload_parser_eof(self):
        out = aiohttp.FlowControlDataQueue(self.stream)
        p = protocol.HttpPayloadParser(out, readall=True)
        assert not p.done

        p.feed_data(b'data')
        p.feed_data(b'line')
        p.feed_eof()
        self.assertEqual(b'dataline', b''.join(d for d, _ in out._buffer))
        self.assertTrue(out.is_eof())
Exemplo n.º 15
0
    def test_parse_length_payload(self):
        out = aiohttp.FlowControlDataQueue(self.stream)
        p = protocol.HttpPayloadParser(out, length=4)
        p.feed_data(b'da')
        p.feed_data(b't')
        eof, tail = p.feed_data(b'aline')

        self.assertEqual(3, len(out._buffer))
        self.assertEqual(b'data', b''.join(d for d, _ in out._buffer))
        self.assertEqual(b'line', tail)
Exemplo n.º 16
0
 def test_parse_chunked_payload_extension(self):
     out = aiohttp.FlowControlDataQueue(self.stream)
     buf = aiohttp.ParserBuffer()
     p = protocol.HttpPayloadParser(None).parse_chunked_payload(out, buf)
     next(p)
     try:
         p.send(b'4;test\r\ndata\r\n4\r\nline\r\n0\r\ntest\r\n')
     except StopIteration:
         pass
     self.assertEqual(b'dataline', b''.join(d for d, _ in out._buffer))
Exemplo n.º 17
0
 def test_http_payload_parser_websocket(self):
     msg = protocol.RawRequestMessage(
         'GET', '/', (1, 1), CIMultiDict([('SEC-WEBSOCKET-KEY1', '13')]),
         None, None)
     out = aiohttp.FlowControlDataQueue(self.stream)
     buf = aiohttp.ParserBuffer()
     p = protocol.HttpPayloadParser(msg)(out, buf)
     next(p)
     self.assertRaises(StopIteration, p.send, b'1234567890')
     self.assertEqual(b'12345678', b''.join(d for d, _ in out._buffer))
Exemplo n.º 18
0
 def test_http_payload_parser_eof(self):
     msg = protocol.RawRequestMessage('GET', '/', (1, 1), [], None, None)
     out = aiohttp.DataQueue()
     buf = aiohttp.ParserBuffer()
     p = protocol.HttpPayloadParser(msg, readall=True)(out, buf)
     next(p)
     p.send(b'data')
     p.send(b'line')
     self.assertRaises(aiohttp.EofStream, p.throw, aiohttp.EofStream())
     self.assertEqual(b'dataline', b''.join(out._buffer))
Exemplo n.º 19
0
 def test_parse_chunked_payload(self):
     out = aiohttp.DataQueue()
     buf = aiohttp.ParserBuffer()
     p = protocol.HttpPayloadParser(None).parse_chunked_payload(out, buf)
     next(p)
     try:
         p.send(b'4\r\ndata\r\n4\r\nline\r\n0\r\ntest\r\n')
     except StopIteration:
         pass
     self.assertEqual(b'dataline', b''.join(out._buffer))
     self.assertEqual(b'', bytes(buf))
Exemplo n.º 20
0
    def test_http_payload_parser_deflate_disabled(self):
        msg = protocol.RawRequestMessage(
            'GET', '/', (1, 1), [('CONTENT-LENGTH', len(self._COMPRESSED))],
            None, 'deflate')

        out = aiohttp.DataQueue()
        buf = aiohttp.ParserBuffer()
        p = protocol.HttpPayloadParser(msg, compression=False)(out, buf)
        next(p)
        self.assertRaises(StopIteration, p.send, self._COMPRESSED)
        self.assertEqual(self._COMPRESSED, b''.join(out._buffer))
Exemplo n.º 21
0
 def test_http_payload_parser_eof(self):
     msg = protocol.RawRequestMessage('GET', '/', (1, 1), CIMultiDict(),
                                      None, None)
     out = aiohttp.FlowControlDataQueue(self.stream)
     buf = aiohttp.ParserBuffer()
     p = protocol.HttpPayloadParser(msg, readall=True)(out, buf)
     next(p)
     p.send(b'data')
     p.send(b'line')
     self.assertRaises(StopIteration, p.throw, aiohttp.EofStream())
     self.assertEqual(b'dataline', b''.join(d for d, _ in out._buffer))
Exemplo n.º 22
0
 def test_http_payload_parser_chunked(self):
     msg = protocol.RawRequestMessage(
         'GET', '/', (1, 1),
         CIMultiDict([('TRANSFER-ENCODING', 'chunked')]), None, None)
     out = aiohttp.FlowControlDataQueue(self.stream)
     buf = aiohttp.ParserBuffer()
     p = protocol.HttpPayloadParser(msg)(out, buf)
     next(p)
     self.assertRaises(StopIteration, p.send,
                       b'4;test\r\ndata\r\n4\r\nline\r\n0\r\ntest\r\n')
     self.assertEqual(b'dataline', b''.join(d for d, _ in out._buffer))
Exemplo n.º 23
0
    def test_parse_eof_payload(self):
        out = aiohttp.DataQueue()
        buf = aiohttp.ParserBuffer()
        p = protocol.HttpPayloadParser(None).parse_eof_payload(out, buf)
        next(p)
        p.send(b'data')
        try:
            p.throw(aiohttp.EofStream())
        except aiohttp.EofStream:
            pass

        self.assertEqual([b'data'], list(out._buffer))
Exemplo n.º 24
0
    def test_http_payload_parser_deflate(self):
        msg = protocol.RawRequestMessage(
            'GET', '/', (1, 1),
            CIMultiDict([('CONTENT-LENGTH', len(self._COMPRESSED))]), None,
            'deflate')

        out = aiohttp.FlowControlDataQueue(self.stream)
        buf = aiohttp.ParserBuffer()
        p = protocol.HttpPayloadParser(msg)(out, buf)
        next(p)
        self.assertRaises(StopIteration, p.send, self._COMPRESSED)
        self.assertEqual(b'data', b''.join(d for d, _ in out._buffer))
Exemplo n.º 25
0
    def test_parse_eof_payload(self):
        out = aiohttp.FlowControlDataQueue(self.stream)
        buf = aiohttp.ParserBuffer()
        p = protocol.HttpPayloadParser(None).parse_eof_payload(out, buf)
        next(p)
        p.send(b'data')
        try:
            p.throw(aiohttp.EofStream())
        except StopIteration:
            pass

        self.assertEqual([(bytearray(b'data'), 4)], list(out._buffer))
Exemplo n.º 26
0
 def test_parse_chunked_payload_chunks(self):
     out = aiohttp.FlowControlDataQueue(self.stream)
     buf = aiohttp.ParserBuffer()
     p = protocol.HttpPayloadParser(None).parse_chunked_payload(out, buf)
     next(p)
     p.send(b'4\r\ndata\r')
     p.send(b'\n4')
     p.send(b'\r')
     p.send(b'\n')
     p.send(b'line\r\n0\r\n')
     self.assertRaises(StopIteration, p.send, b'test\r\n')
     self.assertEqual(b'dataline', b''.join(d for d, _ in out._buffer))
Exemplo n.º 27
0
    def test_http_payload_parser_length(self):
        msg = protocol.RawRequestMessage('GET', '/', (1, 1),
                                         [('CONTENT-LENGTH', '2')], None, None)
        out = aiohttp.DataQueue()
        buf = aiohttp.ParserBuffer()
        p = protocol.HttpPayloadParser(msg)(out, buf)
        next(p)
        try:
            p.send(b'1245')
        except StopIteration:
            pass

        self.assertEqual(b'12', b''.join(out._buffer))
        self.assertEqual(b'45', bytes(buf))
Exemplo n.º 28
0
    def test_parse_length_payload(self):
        out = aiohttp.FlowControlDataQueue(self.stream)
        buf = aiohttp.ParserBuffer()
        p = protocol.HttpPayloadParser(None).parse_length_payload(out, buf, 4)
        next(p)
        p.send(b'da')
        p.send(b't')
        try:
            p.send(b'aline')
        except StopIteration:
            pass

        self.assertEqual(3, len(out._buffer))
        self.assertEqual(b'data', b''.join(d for d, _ in out._buffer))
        self.assertEqual(b'line', bytes(buf))
Exemplo n.º 29
0
 def test_http_payload_parser_length_zero(self):
     out = aiohttp.FlowControlDataQueue(self.stream)
     p = protocol.HttpPayloadParser(out, length=0)
     self.assertTrue(p.done)
     self.assertTrue(out.is_eof())
Exemplo n.º 30
0
 def test_parse_chunked_payload_size_error(self):
     out = aiohttp.FlowControlDataQueue(self.stream)
     buf = aiohttp.ParserBuffer()
     p = protocol.HttpPayloadParser(None).parse_chunked_payload(out, buf)
     next(p)
     self.assertRaises(errors.TransferEncodingError, p.send, b'blah\r\n')