Raise an error if body is not null, has not length and is not streamable.

This commit is contained in:
Casey Davidson
2016-06-08 21:47:34 -07:00
committed by Nate Prewitt
parent bfb202527d
commit 033dfc165d
+2
View File
@@ -526,6 +526,8 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
self.headers['Content-Length'] = builtin_str(length)
elif is_stream and not length:
self.headers['Transfer-Encoding'] = 'chunked'
else:
assert False, "If body is not null, it must either have a length or be streamable"
elif (self.method not in ('GET', 'HEAD')) and (self.headers.get('Content-Length') is None):
self.headers['Content-Length'] = '0'