Merge remote-tracking branch 'origin/master'

This commit is contained in:
Kenneth Reitz
2013-10-24 10:54:48 -04:00
2 changed files with 13 additions and 4 deletions
+5 -4
View File
@@ -324,7 +324,8 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
scheme, auth, host, port, path, query, fragment = parse_url(url)
if not scheme:
raise MissingSchema("Invalid URL %r: No schema supplied" % url)
raise MissingSchema("Invalid URL {0!r}: No schema supplied. "
"Perhaps you meant http://{0}?".format(url))
if not host:
raise InvalidURL("Invalid URL %r: No host supplied" % url)
@@ -407,7 +408,7 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
raise NotImplementedError('Streamed bodies and files are mutually exclusive.')
if length is not None:
self.headers['Content-Length'] = str(length)
self.headers['Content-Length'] = builtin_str(length)
else:
self.headers['Transfer-Encoding'] = 'chunked'
else:
@@ -433,12 +434,12 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
def prepare_content_length(self, body):
if hasattr(body, 'seek') and hasattr(body, 'tell'):
body.seek(0, 2)
self.headers['Content-Length'] = str(body.tell())
self.headers['Content-Length'] = builtin_str(body.tell())
body.seek(0, 0)
elif body is not None:
l = super_len(body)
if l:
self.headers['Content-Length'] = str(l)
self.headers['Content-Length'] = builtin_str(l)
elif self.method not in ('GET', 'HEAD'):
self.headers['Content-Length'] = '0'
+8
View File
@@ -684,6 +684,14 @@ class RequestsTestCase(unittest.TestCase):
self.assertTrue('multipart/form-data' in p.headers['Content-Type'])
def test_autoset_header_values_are_native(self):
data = 'this is a string'
length = '16'
req = requests.Request('POST', httpbin('post'), data=data)
p = req.prepare()
self.assertEqual(p.headers['Content-Length'], length)
class TestContentEncodingDetection(unittest.TestCase):