mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
Merge pull request #2332 from asnelzin/fix-2329
Add overriding Content-Length
This commit is contained in:
+1
-1
@@ -472,7 +472,7 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
|
||||
l = super_len(body)
|
||||
if l:
|
||||
self.headers['Content-Length'] = builtin_str(l)
|
||||
elif self.method not in ('GET', 'HEAD'):
|
||||
elif (self.method not in ('GET', 'HEAD')) and (self.headers.get('Content-Length') is None):
|
||||
self.headers['Content-Length'] = '0'
|
||||
|
||||
def prepare_auth(self, auth, url=''):
|
||||
|
||||
@@ -103,6 +103,14 @@ class RequestsTestCase(unittest.TestCase):
|
||||
head_req = requests.Request('HEAD', httpbin('head')).prepare()
|
||||
assert 'Content-Length' not in head_req.headers
|
||||
|
||||
def test_override_content_length(self):
|
||||
headers = {
|
||||
'Content-Length': 'not zero'
|
||||
}
|
||||
r = requests.Request('POST', httpbin('post'), headers=headers).prepare()
|
||||
assert 'Content-Length' in r.headers
|
||||
assert r.headers['Content-Length'] == 'not zero'
|
||||
|
||||
def test_path_is_not_double_encoded(self):
|
||||
request = requests.Request('GET', "http://0.0.0.0/get/test case").prepare()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user