mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
add enforce_content_length=True default
This commit is contained in:
@@ -434,7 +434,8 @@ class HTTPAdapter(BaseAdapter):
|
||||
preload_content=False,
|
||||
decode_content=False,
|
||||
retries=self.max_retries,
|
||||
timeout=timeout
|
||||
timeout=timeout,
|
||||
enforce_content_length=True
|
||||
)
|
||||
|
||||
# Send the request.
|
||||
@@ -478,7 +479,9 @@ class HTTPAdapter(BaseAdapter):
|
||||
pool=conn,
|
||||
connection=low_conn,
|
||||
preload_content=False,
|
||||
decode_content=False
|
||||
decode_content=False,
|
||||
enforce_content_length=True,
|
||||
request_method=request.method
|
||||
)
|
||||
except:
|
||||
# If we hit any problems here, clean up the connection.
|
||||
|
||||
+6
-2
@@ -28,7 +28,8 @@ from .packages.urllib3.fields import RequestField
|
||||
from .packages.urllib3.filepost import encode_multipart_formdata
|
||||
from .packages.urllib3.util import parse_url
|
||||
from .packages.urllib3.exceptions import (
|
||||
DecodeError, ReadTimeoutError, ProtocolError, LocationParseError)
|
||||
DecodeError, ReadTimeoutError, ProtocolError,
|
||||
LocationParseError, ConnectionError)
|
||||
from .exceptions import (
|
||||
HTTPError, MissingScheme, InvalidURL, ChunkedEncodingError,
|
||||
ContentDecodingError, ConnectionError, StreamConsumedError)
|
||||
@@ -701,7 +702,10 @@ class Response(object):
|
||||
for chunk in self.raw.stream(chunk_size, decode_content=True):
|
||||
yield chunk
|
||||
except ProtocolError as e:
|
||||
raise ChunkedEncodingError(e)
|
||||
if self.headers.get('Transfer-Encoding') == 'chunked':
|
||||
raise ChunkedEncodingError(e)
|
||||
else:
|
||||
raise ConnectionError(e)
|
||||
except DecodeError as e:
|
||||
raise ContentDecodingError(e)
|
||||
except ReadTimeoutError as e:
|
||||
|
||||
@@ -21,7 +21,7 @@ from ._internal_utils import to_native_string
|
||||
from .utils import to_key_val_list, default_headers
|
||||
from .exceptions import (
|
||||
TooManyRedirects, InvalidScheme, ChunkedEncodingError,
|
||||
ContentDecodingError, InvalidHeader)
|
||||
ConnectionError, ContentDecodingError, InvalidHeader)
|
||||
from .packages.urllib3._collections import RecentlyUsedContainer
|
||||
from .structures import CaseInsensitiveDict
|
||||
|
||||
@@ -115,7 +115,7 @@ class SessionRedirectMixin(object):
|
||||
|
||||
try:
|
||||
response.content # Consume socket so it can be released
|
||||
except (ChunkedEncodingError, ContentDecodingError, RuntimeError):
|
||||
except (ChunkedEncodingError, ConnectionError, ContentDecodingError, RuntimeError):
|
||||
response.raw.read(decode_content=False)
|
||||
|
||||
# Don't exceed configured Session.max_redirects.
|
||||
|
||||
Reference in New Issue
Block a user