This repository was archived by the owner on Apr 14, 2022. It is now read-only.
File tree 2 files changed +34
-3
lines changed
2 files changed +34
-3
lines changed Original file line number Diff line number Diff line change 15
15
16
16
17
17
def consume_socket (sock , chunks = 65536 ):
18
- while not sock .recv (chunks ).endswith (b"\r \n \r \n " ):
19
- pass
18
+ consumed = bytearray ()
19
+ while True :
20
+ b = sock .recv (chunks )
21
+ consumed += b
22
+ if b .endswith (b"\r \n \r \n " ):
23
+ break
24
+ return consumed
20
25
21
26
22
27
class SocketDummyServerTestCase (object ):
Original file line number Diff line number Diff line change 2
2
3
3
from urllib3 import HTTPConnectionPool
4
4
from urllib3 .exceptions import InvalidBodyError
5
- from dummyserver .testcase import SocketDummyServerTestCase
5
+ from urllib3 .util .retry import Retry
6
+ from dummyserver .testcase import SocketDummyServerTestCase , consume_socket
6
7
import pytest
7
8
8
9
@@ -97,3 +98,28 @@ def test_provides_default_host_header(self):
97
98
98
99
host_headers = [x for x in header_lines if x .startswith (b"host" )]
99
100
assert len (host_headers ) == 1
101
+
102
+ def test_preserve_chunked_on_retry (self ):
103
+ self .chunked_requests = 0
104
+
105
+ def socket_handler (listener ):
106
+ for _ in range (2 ):
107
+ sock = listener .accept ()[0 ]
108
+ request = consume_socket (sock )
109
+ if b"transfer-encoding: chunked" in request .split (b"\r \n " ):
110
+ self .chunked_requests += 1
111
+
112
+ sock .send (b"HTTP/1.1 404 Not Found\r \n \r \n " )
113
+ sock .close ()
114
+
115
+ self ._start_server (socket_handler )
116
+ with HTTPConnectionPool (self .host , self .port ) as pool :
117
+ retries = Retry (total = 1 , raise_on_status = False , status_forcelist = [404 ])
118
+ pool .urlopen (
119
+ "GET" ,
120
+ "/" ,
121
+ body = iter ([b"chunk1" , b"chunk2" ]),
122
+ preload_content = False ,
123
+ retries = retries ,
124
+ )
125
+ assert self .chunked_requests == 2
You can’t perform that action at this time.
0 commit comments