Here are the examples of the python api aiohttp.protocol.HttpRequestParser taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
9 Examples
3
Example 1
Project: aiohttp Source File: test_http_parser.py
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')
3
Example 2
Project: aiohttp Source File: test_http_parser.py
def test_http_request_parser(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
result = out._buffer[0][0]
self.assertEqual(
('GET', '/path', (1, 1), CIMultiDict(), [], False, None),
result)
3
Example 3
Project: aiohttp Source File: test_http_parser.py
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, length = out._buffer[0]
self.assertEqual(len(msg), length)
self.assertEqual(
('GET', '/path', (1, 1),
CIMultiDict([('X-TEST', 'тест')]),
[(b'X-TEST', 'тест'.encode('utf-8'))],
False, None),
result)
3
Example 4
Project: aiohttp Source File: test_http_parser.py
def test_http_request_parser_non_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('cp1251')
try:
p.send(msg)
except StopIteration:
pass
result, length = out._buffer[0]
self.assertEqual(len(msg), length)
self.assertEqual(
('GET', '/path', (1, 1),
CIMultiDict([('X-TEST', 'тест'.encode('cp1251').decode(
'utf-8', 'surrogateescape'))]),
[(b'X-TEST', 'тест'.encode('cp1251'))],
False, None),
result)
3
Example 5
Project: aiohttp Source File: test_http_parser.py
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)
3
Example 6
Project: aiohttp Source File: test_http_parser.py
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])
3
Example 7
Project: aiohttp Source File: test_http_parser.py
def test_http_request_parser_bad_status_line(self):
out = aiohttp.FlowControlDataQueue(self.stream)
buf = aiohttp.ParserBuffer()
p = protocol.HttpRequestParser()(out, buf)
next(p)
self.assertRaises(
errors.BadStatusLine, p.send, b'\r\n\r\n')
3
Example 8
Project: aiohttp Source File: test_http_parser.py
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')
3
Example 9
Project: aiohttp Source File: test_http_parser.py
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')