This should take care of #1266

We were sending 'None' as the Content-Length on requests where the body was a
generator. This commit should prevent that entirely.
This commit is contained in:
Ian Cordasco
2013-03-27 23:26:11 -04:00
parent 478d49027f
commit 1d5c4f3f0f
+5 -3
View File
@@ -349,7 +349,7 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
])
try:
length = str(super_len(data))
length = super_len(data)
except (TypeError, AttributeError):
length = False
@@ -360,7 +360,7 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
raise NotImplementedError('Streamed bodies and files are mutually exclusive.')
if length:
self.headers['Content-Length'] = length
self.headers['Content-Length'] = str(length)
else:
self.headers['Transfer-Encoding'] = 'chunked'
# Check if file, fo, generator, iterator.
@@ -392,7 +392,9 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
self.headers['Content-Length'] = str(body.tell())
body.seek(0, 0)
elif body is not None:
self.headers['Content-Length'] = str(len(body))
l = super_len(body)
if l:
self.headers['Content-Length'] = super_len(l)
elif self.method not in ('GET', 'HEAD'):
self.headers['Content-Length'] = '0'