mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
Use buffering for HTTP responses on chunked requests
For non-chunked requests, the request is performed using the 'urlopen' method that underlying uses buffering for the HTTP responses (for Python 2.7+ versions). For chunked requests though, the request is made via a different code path and so the 'getresponse' method is called without using buffering. So, the response is consumed per single byte via a recv() call on the underlying socket. This patch, fixes that issue to mimic the non-chucked request behavior.
This commit is contained in:
@@ -394,7 +394,15 @@ class HTTPAdapter(BaseAdapter):
|
|||||||
low_conn.send(b'\r\n')
|
low_conn.send(b'\r\n')
|
||||||
low_conn.send(b'0\r\n\r\n')
|
low_conn.send(b'0\r\n\r\n')
|
||||||
|
|
||||||
r = low_conn.getresponse()
|
# Receive the response from the server
|
||||||
|
try:
|
||||||
|
# For Python 2.7+ versions, use buffering of HTTP
|
||||||
|
# responses
|
||||||
|
r = conn.getresponse(buffering=True)
|
||||||
|
except TypeError:
|
||||||
|
# For compatibility with Python 2.6 versions and back
|
||||||
|
r = conn.getresponse()
|
||||||
|
|
||||||
resp = HTTPResponse.from_httplib(
|
resp = HTTPResponse.from_httplib(
|
||||||
r,
|
r,
|
||||||
pool=conn,
|
pool=conn,
|
||||||
|
|||||||
Reference in New Issue
Block a user