From 34f6088c8f3f2bac942c84ce2ffa92dfdee5aa4e Mon Sep 17 00:00:00 2001 From: Alexander Nelzin Date: Wed, 12 Nov 2014 15:23:23 +0300 Subject: [PATCH 1/2] Added test for overriding Content-Length. --- test_requests.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test_requests.py b/test_requests.py index b2e12d06..4a05cb2e 100755 --- a/test_requests.py +++ b/test_requests.py @@ -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() From ee50afef59ca47879144448ae056a2836f3d4534 Mon Sep 17 00:00:00 2001 From: Alexander Nelzin Date: Wed, 12 Nov 2014 15:35:27 +0300 Subject: [PATCH 2/2] Fixed. --- requests/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requests/models.py b/requests/models.py index 3f6a4f92..2370b67f 100644 --- a/requests/models.py +++ b/requests/models.py @@ -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=''):