@@ -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 \n Host: localhost:1234\r \n Content-Type: text/pl' ,
430+ b'ain; charset=utf-8\r \n X-Empty-Header: \r \n Connection: close\r \n ' ,
431+ b'Content-Length: 10\r \n \r \n 1234567890' ,
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
423458class TestUrlParser (unittest .TestCase ):
424459
0 commit comments