Merge pull request #5496 from dbaxa/optimise-prepare-body

Avoid an unnecessary computation of the length of data for non-stream requests (which determine content-length based upon body content).
This commit is contained in:
Nate Prewitt
2020-06-17 08:21:38 -07:00
committed by GitHub
+5 -5
View File
@@ -473,12 +473,12 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
not isinstance(data, (basestring, list, tuple, Mapping))
])
try:
length = super_len(data)
except (TypeError, AttributeError, UnsupportedOperation):
length = None
if is_stream:
try:
length = super_len(data)
except (TypeError, AttributeError, UnsupportedOperation):
length = None
body = data
if getattr(body, 'tell', None) is not None: