Skip to content

Commit b44793d

Browse files
shadycuzjamespiclverrall
authored andcommitted
Use urllib3 native chunking ability (psf#6226)
* Fix psf#3844 * Use urllib for chunked --------- Co-authored-by: James Pickering <[email protected]> Co-authored-by: Leon Verrall <[email protected]>
1 parent d63fee2 commit b44793d

File tree

1 file changed

+13
-58
lines changed

1 file changed

+13
-58
lines changed

requests/adapters.py

+13-58
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from urllib3.exceptions import ReadTimeoutError, ResponseError
2323
from urllib3.exceptions import SSLError as _SSLError
2424
from urllib3.poolmanager import PoolManager, proxy_from_url
25-
from urllib3.response import HTTPResponse
2625
from urllib3.util import Timeout as TimeoutSauce
2726
from urllib3.util import parse_url
2827
from urllib3.util.retry import Retry
@@ -485,63 +484,19 @@ def send(
485484
timeout = TimeoutSauce(connect=timeout, read=timeout)
486485

487486
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-
)
501-
502-
# Send the request.
503-
else:
504-
if hasattr(conn, "proxy_pool"):
505-
conn = conn.proxy_pool
506-
507-
low_conn = conn._get_conn(timeout=DEFAULT_POOL_TIMEOUT)
508-
509-
try:
510-
skip_host = "Host" in request.headers
511-
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 server
531-
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-
raise
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+
)
545500

546501
except (ProtocolError, OSError) as err:
547502
raise ConnectionError(err, request=request)

0 commit comments

Comments
 (0)