Skip to content

Commit

Permalink
Avoid an unnecessary computation of the length of data for non-stream…
Browse files Browse the repository at this point in the history
… requests (which determines content-length based upon body content).
  • Loading branch information
dbaxa committed Jun 16, 2020
1 parent 737dd0c commit 71a05cf
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions requests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,12 +473,12 @@ def prepare_body(self, data, files, json=None):
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:
Expand Down

0 comments on commit 71a05cf

Please sign in to comment.