Skip to content

Commit 61a4346

Browse files
committed
Add fragmented request unittest
1 parent def67ef commit 61a4346

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/test_parser.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,41 @@ def test_parser_request_4(self):
419419
with self.assertRaisesRegex(TypeError, 'a bytes-like object'):
420420
p.feed_data('POST HTTP/1.2')
421421

422+
def test_parser_request_fragmented(self):
423+
m = mock.Mock()
424+
headers = {}
425+
m.on_header.side_effect = headers.__setitem__
426+
p = httptools.HttpRequestParser(m)
427+
428+
REQUEST = (
429+
b'PUT / HTTP/1.1\r\nHost: localhost:1234\r\nContent-Type: text/pl',
430+
b'ain; charset=utf-8\r\nX-Empty-Header: \r\nConnection: close\r\n',
431+
b'Content-Length: 10\r\n\r\n1234567890',
432+
)
433+
434+
p.feed_data(REQUEST[0])
435+
436+
m.on_message_begin.assert_called_once_with()
437+
m.on_url.assert_called_once_with(b'/')
438+
self.assertEqual(headers, {b'Host': b'localhost:1234'})
439+
440+
p.feed_data(REQUEST[1])
441+
self.assertEqual(
442+
headers,
443+
{b'Host': b'localhost:1234',
444+
b'Content-Type': b'text/plain; charset=utf-8',
445+
b'X-Empty-Header': b''})
446+
447+
p.feed_data(REQUEST[2])
448+
self.assertEqual(
449+
headers,
450+
{b'Host': b'localhost:1234',
451+
b'Content-Type': b'text/plain; charset=utf-8',
452+
b'X-Empty-Header': b'',
453+
b'Connection': b'close',
454+
b'Content-Length': b'10'})
455+
m.on_message_complete.assert_called_once_with()
456+
422457

423458
class TestUrlParser(unittest.TestCase):
424459

0 commit comments

Comments
 (0)