diff options
Diffstat (limited to 'pip/_vendor/requests/models.py')
-rw-r--r-- | pip/_vendor/requests/models.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/pip/_vendor/requests/models.py b/pip/_vendor/requests/models.py index 4bcbc5484..fe4bec1bd 100644 --- a/pip/_vendor/requests/models.py +++ b/pip/_vendor/requests/models.py @@ -103,8 +103,10 @@ class RequestEncodingMixin(object): """Build the body for a multipart/form-data request. Will successfully encode files when passed as a dict or a list of - 2-tuples. Order is retained if data is a list of 2-tuples but arbitrary + tuples. Order is retained if data is a list of tuples but arbitrary if parameters are supplied as a dict. + The tuples may be 2-tuples (filename, fileobj), 3-tuples (filename, fileobj, contentype) + or 4-tuples (filename, fileobj, contentype, custom_headers). """ if (not files): @@ -463,9 +465,11 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin): def prepare_content_length(self, body): if hasattr(body, 'seek') and hasattr(body, 'tell'): + curr_pos = body.tell() body.seek(0, 2) - self.headers['Content-Length'] = builtin_str(body.tell()) - body.seek(0, 0) + end_pos = body.tell() + self.headers['Content-Length'] = builtin_str(max(0, end_pos - curr_pos)) + body.seek(curr_pos, 0) elif body is not None: l = super_len(body) if l: |