Here are the examples of the python api aiohttp.protocol.HttpResponseParser taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
10 Examples
3
Example 1
Project: aiohttp Source File: test_http_parser.py
def test_http_response_parser_utf8(self):
out = aiohttp.FlowControlDataQueue(self.stream)
buf = aiohttp.ParserBuffer()
p = protocol.HttpResponseParser()(out, buf)
next(p)
msg = 'HTTP/1.1 200 Ok\r\nx-test:тест\r\n\r\n'.encode('utf-8')
try:
p.send(msg)
except StopIteration:
pass
v, s, r, h = out._buffer[0][0][:4]
self.assertEqual(v, (1, 1))
self.assertEqual(s, 200)
self.assertEqual(r, 'Ok')
self.assertEqual(h, CIMultiDict([('X-TEST', 'тест')]))
3
Example 2
Project: aiohttp Source File: test_http_parser.py
def test_http_response_parser_bad_status_line(self):
out = aiohttp.FlowControlDataQueue(self.stream)
buf = aiohttp.ParserBuffer()
p = protocol.HttpResponseParser()(out, buf)
next(p)
self.assertRaises(errors.BadStatusLine, p.send, b'\r\n\r\n')
3
Example 3
Project: aiohttp Source File: test_http_parser.py
def test_http_response_parser_bad_status_line_too_long(self):
out = aiohttp.FlowControlDataQueue(self.stream)
buf = aiohttp.ParserBuffer()
p = protocol.HttpResponseParser(
max_headers=2, max_line_size=2)(out, buf)
next(p)
self.assertRaises(
errors.LineTooLong, p.send, b'HTTP/1.1 200 Ok\r\n\r\n')
3
Example 4
Project: aiohttp Source File: test_http_parser.py
def test_http_response_parser_bad_status_line_eof(self):
out = aiohttp.FlowControlDataQueue(self.stream)
buf = aiohttp.ParserBuffer()
p = protocol.HttpResponseParser()(out, buf)
next(p)
self.assertRaises(aiohttp.EofStream, p.throw, aiohttp.EofStream())
3
Example 5
Project: aiohttp Source File: test_http_parser.py
def test_http_response_parser_bad_version(self):
out = aiohttp.FlowControlDataQueue(self.stream)
buf = aiohttp.ParserBuffer()
p = protocol.HttpResponseParser()(out, buf)
next(p)
with self.assertRaises(errors.BadStatusLine) as cm:
p.send(b'HT/11 200 Ok\r\n\r\n')
self.assertEqual('HT/11 200 Ok', cm.exception.args[0])
3
Example 6
Project: aiohttp Source File: test_http_parser.py
def test_http_response_parser_no_reason(self):
out = aiohttp.FlowControlDataQueue(self.stream)
buf = aiohttp.ParserBuffer()
p = protocol.HttpResponseParser()(out, buf)
next(p)
try:
p.send(b'HTTP/1.1 200\r\n\r\n')
except StopIteration:
pass
v, s, r = out._buffer[0][0][:3]
self.assertEqual(v, (1, 1))
self.assertEqual(s, 200)
self.assertEqual(r, '')
3
Example 7
Project: aiohttp Source File: test_http_parser.py
def test_http_response_parser_bad(self):
out = aiohttp.FlowControlDataQueue(self.stream)
buf = aiohttp.ParserBuffer()
p = protocol.HttpResponseParser()(out, buf)
next(p)
with self.assertRaises(errors.BadStatusLine) as cm:
p.send(b'HTT/1\r\n\r\n')
self.assertIn('HTT/1', str(cm.exception))
3
Example 8
Project: aiohttp Source File: test_http_parser.py
def test_http_response_parser_code_under_100(self):
out = aiohttp.FlowControlDataQueue(self.stream)
buf = aiohttp.ParserBuffer()
p = protocol.HttpResponseParser()(out, buf)
next(p)
with self.assertRaises(errors.BadStatusLine) as cm:
p.send(b'HTTP/1.1 99 test\r\n\r\n')
self.assertIn('HTTP/1.1 99 test', str(cm.exception))
3
Example 9
Project: aiohttp Source File: test_http_parser.py
def test_http_response_parser_code_above_999(self):
out = aiohttp.FlowControlDataQueue(self.stream)
buf = aiohttp.ParserBuffer()
p = protocol.HttpResponseParser()(out, buf)
next(p)
with self.assertRaises(errors.BadStatusLine) as cm:
p.send(b'HTTP/1.1 9999 test\r\n\r\n')
self.assertIn('HTTP/1.1 9999 test', str(cm.exception))
3
Example 10
Project: aiohttp Source File: test_http_parser.py
def test_http_response_parser_code_not_int(self):
out = aiohttp.FlowControlDataQueue(self.stream)
buf = aiohttp.ParserBuffer()
p = protocol.HttpResponseParser()(out, buf)
next(p)
with self.assertRaises(errors.BadStatusLine) as cm:
p.send(b'HTTP/1.1 ttt test\r\n\r\n')
self.assertIn('HTTP/1.1 ttt test', str(cm.exception))