Revert "Use urllib for chunked requests"
Before adoption: this commit came in with the history the project adopted, so no landing records it.
This reverts commit 2da7fe08586aeaff614c017a9a834a22c937384a.
authored by Nate Prewitt · committed by Seth Michael Larson · parent b15056d · Browse files · 1 file·+58 added−13 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+58 added−13 removed
- other:+58 added−13 removed
Provenance
- Commit
24bcb9e- Tree
b82f88f- Author
Nate Prewitt <Nate.Prewitt@gmail.com>- Committer
Seth Michael Larson <sethmichaellarson@gmail.com>- Parent
b15056d
1 file changed+58 added−13 removed
modified:requests/adapters.py+58 added-13 removed
433 unmodified lines434 else:435 timeout = TimeoutSauce(connect=timeout, read=timeout)436 437 try:438- resp = conn.urlopen(439- method=request.method,440- url=url,441- body=request.body,442- headers=request.headers,443- redirect=False,444- assert_same_host=False,445- preload_content=False,446- decode_content=False,447- retries=self.max_retries,448- timeout=timeout,449- chunked=chunked450- )438+ if not chunked:439+ resp = conn.urlopen(440+ method=request.method,441+ url=url,442+ body=request.body,443+ headers=request.headers,444+ redirect=False,445+ assert_same_host=False,446+ preload_content=False,447+ decode_content=False,448+ retries=self.max_retries,449+ timeout=timeout450+ )451 452+ # Send the request.453+ else:454+ if hasattr(conn, 'proxy_pool'):455+ conn = conn.proxy_pool456+457+ low_conn = conn._get_conn(timeout=DEFAULT_POOL_TIMEOUT)458+459+ try:460+ low_conn.putrequest(request.method,461+ url,462+ skip_accept_encoding=True)463+464+ for header, value in request.headers.items():465+ low_conn.putheader(header, value)466+467+ low_conn.endheaders()468+469+ for i in request.body:470+ low_conn.send(hex(len(i))[2:].encode('utf-8'))471+ low_conn.send(b'\r\n')472+ low_conn.send(i)473+ low_conn.send(b'\r\n')474+ low_conn.send(b'0\r\n\r\n')475+476+ # Receive the response from the server477+ try:478+ # For Python 2.7, use buffering of HTTP responses479+ r = low_conn.getresponse(buffering=True)480+ except TypeError:481+ # For compatibility with Python 3.3+482+ r = low_conn.getresponse()483+484+ resp = HTTPResponse.from_httplib(485+ r,486+ pool=conn,487+ connection=low_conn,488+ preload_content=False,489+ decode_content=False490+ )491+ except:492+ # If we hit any problems here, clean up the connection.493+ # Then, reraise so that we can handle the actual exception.494+ low_conn.close()495+ raise496+497 except (ProtocolError, socket.error) as err:498 raise ConnectionError(err, request=request)499 500 except MaxRetryError as e:33 unmodified lines