Better connection behaviour for chunked upload.
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Cory Benfield · committed by Cory Benfield · parent 097121d · Browse files · 1 file·+29 added−17 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+29 added−17 removed
- other:+29 added−17 removed
Provenance
- Commit
31c0962- Tree
76def68- Author
Cory Benfield <lukasaoz@gmail.com>- Committer
Cory Benfield <lukasaoz@gmail.com>- Parent
097121d
1 file changed+29 added−17 removed
modified:requests/adapters.py+29 added-17 removed
325 unmodified lines326 if hasattr(conn, 'proxy_pool'):327 conn = conn.proxy_pool328 329 low_conn = conn._get_conn(timeout=timeout)330- low_conn.putrequest(request.method, url, skip_accept_encoding=True)330 332- for header, value in request.headers.items():333- low_conn.putheader(header, value)331+ try:332+ low_conn.putrequest(request.method,333+ url,334+ skip_accept_encoding=True)335 335- low_conn.endheaders()336+ for header, value in request.headers.items():337+ low_conn.putheader(header, value)338 337- for i in request.body:338- low_conn.send(hex(len(i))[2:].encode('utf-8'))339- low_conn.send(b'\r\n')340- low_conn.send(i)341- low_conn.send(b'\r\n')342- low_conn.send(b'0\r\n\r\n')339+ low_conn.endheaders()340 344- r = low_conn.getresponse()345- resp = HTTPResponse.from_httplib(r,346- pool=conn,347- connection=low_conn,348- preload_content=False,349- decode_content=False350- )341+ for i in request.body:342+ low_conn.send(hex(len(i))[2:].encode('utf-8'))343+ low_conn.send(b'\r\n')344+ low_conn.send(i)345+ low_conn.send(b'\r\n')346+ low_conn.send(b'0\r\n\r\n')347 348+ r = low_conn.getresponse()349+ resp = HTTPResponse.from_httplib(r,350+ pool=conn,351+ connection=low_conn,352+ preload_content=False,353+ decode_content=False354+ )355+ except:356+ # If we hit any problems here, clean up the connection.357+ # Then, reraise so that we can handle the actual exception.358+ low_conn.close()359+ raise360+ else:361+ # All is well, return the connection to the pool.362+ conn._put_conn(low_conn)363+364 except socket.error as sockerr:365 raise ConnectionError(sockerr)366 367 except MaxRetryError as e:19 unmodified lines