99headers = b"HTTP/1.0 200 OK\r \n Transfer-Encoding: chunked\r \n \r \n "
1010
1111
12- def _chunk (response , split ):
12+ def _chunk (response , split , extra = b"" ):
1313 i = 0
1414 chunked = b""
1515 while i < len (response ):
@@ -19,18 +19,22 @@ def _chunk(response, split):
1919 chunk_size = remaining
2020 new_i = i + chunk_size
2121 chunked += (
22- hex (chunk_size )[2 :].encode ("ascii" ) + b"\r \n " + response [i :new_i ] + b"\r \n "
22+ hex (chunk_size )[2 :].encode ("ascii" )
23+ + extra
24+ + b"\r \n "
25+ + response [i :new_i ]
26+ + b"\r \n "
2327 )
2428 i = new_i
2529 # The final chunk is zero length.
2630 chunked += b"0\r \n \r \n "
2731 return chunked
2832
2933
30- def test_get_text ( ):
34+ def do_test_get_text ( extra = b"" ):
3135 pool = mocket .MocketPool ()
3236 pool .getaddrinfo .return_value = ((None , None , None , None , (ip , 80 )),)
33- c = _chunk (text , 33 )
37+ c = _chunk (text , 33 , extra )
3438 print (c )
3539 sock = mocket .Mocket (headers + c )
3640 pool .socket .return_value = sock
@@ -54,11 +58,19 @@ def test_get_text():
5458 assert r .text == str (text , "utf-8" )
5559
5660
57- def test_close_flush ():
61+ def test_get_text ():
62+ do_test_get_text ()
63+
64+
65+ def test_get_text_extra ():
66+ do_test_get_text (b";blahblah; blah" )
67+
68+
69+ def do_test_close_flush (extra = b"" ):
5870 """Test that a chunked response can be closed even when the request contents were not accessed."""
5971 pool = mocket .MocketPool ()
6072 pool .getaddrinfo .return_value = ((None , None , None , None , (ip , 80 )),)
61- c = _chunk (text , 33 )
73+ c = _chunk (text , 33 , extra )
6274 print (c )
6375 sock = mocket .Mocket (headers + c )
6476 pool .socket .return_value = sock
@@ -81,3 +93,11 @@ def test_close_flush():
8193 )
8294
8395 r .close ()
96+
97+
98+ def test_close_flush ():
99+ do_test_close_flush ()
100+
101+
102+ def test_close_flush_extra ():
103+ do_test_close_flush (b";blahblah; blah" )
0 commit comments