Esempio n. 1
0
def create_request(raw_request_lines):
    """
  :param raw_request_lines: HTTP Request lines without line ends
  :type  raw_request_lines: list(str)

  :rtype: Request
  """
    class ParserOut:
        """
    :param message:
    :type  message: protocol.RawRequestMessage
    """
        def feed_data(po, m, _):
            po.message = m

        def feed_eof(po, *args):
            pass

    raw_request = "\r\n".join(raw_request_lines + ["\r\n"]).encode("utf-8")

    po = ParserOut()
    p = protocol.HttpRequestParser()

    asyncio.get_event_loop() \
      .run_until_complete(p(po, parsers.ParserBuffer(raw_request)))

    return Request(None, po.message, streams.EmptyStreamReader(), None, None,
                   None)
Esempio n. 2
0
 def test_http_request_parser_bad_method(self):
     out = aiohttp.FlowControlDataQueue(self.stream)
     buf = aiohttp.ParserBuffer()
     p = protocol.HttpRequestParser()(out, buf)
     next(p)
     self.assertRaises(errors.BadStatusLine, p.send,
                       b'!12%()+=~$ /get HTTP/1.1\r\n\r\n')
Esempio n. 3
0
 def test_http_request_parser_bad_version(self):
     out = aiohttp.FlowControlDataQueue(self.stream)
     buf = aiohttp.ParserBuffer()
     p = protocol.HttpRequestParser()(out, buf)
     next(p)
     self.assertRaises(errors.BadStatusLine, p.send,
                       b'GET //get HT/11\r\n\r\n')
Esempio n. 4
0
    def _test_http_request_parser_max_headers(self):
        p = protocol.HttpRequestParser(8190, 20, 8190)

        self.assertRaises(
            errors.LineTooLong, p.parse_message,
            b'get /path HTTP/1.1\r\ntest: line\r\ntest2: data\r\n\r\n'.split(
                b'\r\n'))
Esempio n. 5
0
 def test_http_request_parser_utf8(self):
     p = protocol.HttpRequestParser()
     msg = 'get /path HTTP/1.1\r\nx-test:тест\r\n\r\n'.encode('utf-8')
     result = p.parse_message(msg.split(b'\r\n'))
     self.assertEqual(
         ('GET', '/path', (1, 1), CIMultiDict([('X-TEST', 'тест')]), [
             (b'X-TEST', 'тест'.encode('utf-8'))
         ], False, None, False, False), result)
Esempio n. 6
0
    def test_http_request_parser_max_headers(self):
        out = aiohttp.FlowControlDataQueue(self.stream)
        buf = aiohttp.ParserBuffer()
        p = protocol.HttpRequestParser(8190, 20, 8190)(out, buf)
        next(p)

        self.assertRaises(
            errors.LineTooLong, p.send,
            b'get /path HTTP/1.1\r\ntest: line\r\ntest2: data\r\n\r\n')
Esempio n. 7
0
 def test_http_request_parser_two_slashes(self):
     out = aiohttp.FlowControlDataQueue(self.stream)
     buf = aiohttp.ParserBuffer()
     p = protocol.HttpRequestParser()(out, buf)
     next(p)
     try:
         p.send(b'get //path HTTP/1.1\r\n\r\n')
     except StopIteration:
         pass
     self.assertEqual(('GET', '//path', (1, 1), CIMultiDict(), False, None),
                      out._buffer[0][0])
Esempio n. 8
0
 def test_http_request_parser_eof(self):
     # HttpRequestParser does fail on EofStream()
     out = aiohttp.FlowControlDataQueue(self.stream)
     buf = aiohttp.ParserBuffer()
     p = protocol.HttpRequestParser()(out, buf)
     next(p)
     p.send(b'get /path HTTP/1.1\r\n')
     try:
         p.throw(aiohttp.EofStream())
     except aiohttp.EofStream:
         pass
     self.assertFalse(out._buffer)
Esempio n. 9
0
 def test_http_request_parser(self):
     out = aiohttp.DataQueue()
     buf = aiohttp.ParserBuffer()
     p = protocol.HttpRequestParser()(out, buf)
     next(p)
     try:
         p.send(b'get /path HTTP/1.1\r\n\r\n')
     except StopIteration:
         pass
     result = out._buffer[0]
     self.assertEqual(('GET', '/path', (1, 1), deque(), False, None),
                      result)
Esempio n. 10
0
 def test_http_request_parser_utf8(self):
     out = aiohttp.FlowControlDataQueue(self.stream)
     buf = aiohttp.ParserBuffer()
     p = protocol.HttpRequestParser()(out, buf)
     next(p)
     msg = 'get /path HTTP/1.1\r\nx-test:тест\r\n\r\n'.encode('utf-8')
     try:
         p.send(msg)
     except StopIteration:
         pass
     result = out._buffer[0]
     self.assertEqual(
         ('GET', '/path',
          (1, 1), CIMultiDict([('X-TEST', 'тест')]), False, None), result)
Esempio n. 11
0
 def test_http_request_parser_bad_version(self):
     p = protocol.HttpRequestParser()
     self.assertRaises(errors.BadStatusLine, p.parse_message,
                       b'GET //get HT/11\r\n\r\n'.split(b'\r\n'))
Esempio n. 12
0
 def test_http_request_parser_bad_method(self):
     p = protocol.HttpRequestParser()
     self.assertRaises(errors.BadStatusLine, p.parse_message,
                       b'!12%()+=~$ /get HTTP/1.1\r\n\r\n'.split(b'\r\n'))
Esempio n. 13
0
 def test_http_request_parser_bad_status_line(self):
     p = protocol.HttpRequestParser()
     self.assertRaises(errors.BadStatusLine, p.parse_message,
                       b'\r\n\r\n'.split(b'\r\n'))
Esempio n. 14
0
 def test_http_request_parser_two_slashes(self):
     p = protocol.HttpRequestParser()
     result = p.parse_message(b'get //path HTTP/1.1\r\n\r\n'.split(b'\r\n'))
     self.assertEqual(
         ('GET', '//path',
          (1, 1), CIMultiDict(), [], False, None, False, False), result)
Esempio n. 15
0
 def test_http_request_parser_eof(self):
     # HttpRequestParser does fail on EofStream()
     p = protocol.HttpRequestParser()
     p.parse_message(b'get /path HTTP/1.1\r\n'.split(b'\r\n'))
Esempio n. 16
0
 def test_http_request_parser_bad_status_line(self):
     out = aiohttp.DataQueue()
     buf = aiohttp.ParserBuffer()
     p = protocol.HttpRequestParser()(out, buf)
     next(p)
     self.assertRaises(errors.BadStatusLine, p.send, b'\r\n\r\n')