Use urllib3 native chunking ability (#6226)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* Fix #3844 * Use urllib for chunked ---------
authored by Levi · committed by GitHub · parent 7f694b7 · Browse files · 1 file·+13 added−58 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Trailers
- Co-authored-by: James Pickering <james.pickering@xml-solutions.com>
- Co-authored-by: Leon Verrall <LVerrall@slb.com>
Diff stats
1 file+13 added−58 removed
- other:+13 added−58 removed
Provenance
- Commit
26bea1e- Tree
55d4583- Author
Levi <shadycuz@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
7f694b7
1 file changed+13 added−58 removed
modified:requests/adapters.py+13 added-58 removed
20 unmodified lines21 from urllib3.exceptions import ProxyError as _ProxyError22 from urllib3.exceptions import ReadTimeoutError, ResponseError23 from urllib3.exceptions import SSLError as _SSLError24 from urllib3.poolmanager import PoolManager, proxy_from_url25-from urllib3.response import HTTPResponse25 from urllib3.util import Timeout as TimeoutSauce26 from urllib3.util import parse_url27 from urllib3.util.retry import Retry28 454 unmodified lines483 else:484 timeout = TimeoutSauce(connect=timeout, read=timeout)485 486 try:488- if not chunked:489- resp = conn.urlopen(490- method=request.method,491- url=url,492- body=request.body,493- headers=request.headers,494- redirect=False,495- assert_same_host=False,496- preload_content=False,497- decode_content=False,498- retries=self.max_retries,499- timeout=timeout,500- )487+ resp = conn.urlopen(488+ method=request.method,489+ url=url,490+ body=request.body,491+ headers=request.headers,492+ redirect=False,493+ assert_same_host=False,494+ preload_content=False,495+ decode_content=False,496+ retries=self.max_retries,497+ timeout=timeout,498+ chunked=chunked,499+ )500 502- # Send the request.503- else:504- if hasattr(conn, "proxy_pool"):505- conn = conn.proxy_pool506-507- low_conn = conn._get_conn(timeout=DEFAULT_POOL_TIMEOUT)508-509- try:510- skip_host = "Host" in request.headers511- low_conn.putrequest(512- request.method,513- url,514- skip_accept_encoding=True,515- skip_host=skip_host,516- )517-518- for header, value in request.headers.items():519- low_conn.putheader(header, value)520-521- low_conn.endheaders()522-523- for i in request.body:524- low_conn.send(hex(len(i))[2:].encode("utf-8"))525- low_conn.send(b"\r\n")526- low_conn.send(i)527- low_conn.send(b"\r\n")528- low_conn.send(b"0\r\n\r\n")529-530- # Receive the response from the server531- r = low_conn.getresponse()532-533- resp = HTTPResponse.from_httplib(534- r,535- pool=conn,536- connection=low_conn,537- preload_content=False,538- decode_content=False,539- )540- except Exception:541- # If we hit any problems here, clean up the connection.542- # Then, raise so that we can handle the actual exception.543- low_conn.close()544- raise545-501 except (ProtocolError, OSError) as err:502 raise ConnectionError(err, request=request)503 504 except MaxRetryError as e:35 unmodified lines