add enforce_content_length=True default

This commit is contained in:
Nate Prewitt
2016-11-15 11:27:29 -07:00
parent 973a7b1cd0
commit 84d99f01f5
3 changed files with 13 additions and 6 deletions
+5 -2
View File
@@ -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
View File
@@ -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:
+2 -2
View File
@@ -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.