From: Johnny Goodnow Date: Fri, 25 Jan 2013 05:10:12 +0000 (-0800) Subject: Remove default Content-Length from GET requests. X-Git-Tag: v1.2.0~67^2~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=44b1e7ebeabdf28ad1abccca1ef06eefe84d334c;p=services%2Fpython-requests.git Remove default Content-Length from GET requests. Fix #1051. --- diff --git a/requests/models.py b/requests/models.py index 9926045..b05ef25 100644 --- a/requests/models.py +++ b/requests/models.py @@ -386,13 +386,14 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin): self.body = body def prepare_content_length(self, body): - self.headers['Content-Length'] = '0' if hasattr(body, 'seek') and hasattr(body, 'tell'): body.seek(0, 2) self.headers['Content-Length'] = str(body.tell()) body.seek(0, 0) elif body is not None: self.headers['Content-Length'] = str(len(body)) + elif self.method in ('POST', 'PUT'): + self.headers['Content-Length'] = '0' def prepare_auth(self, auth): """Prepares the given HTTP auth data.""" diff --git a/test_requests.py b/test_requests.py index c974e98..24cbc13 100644 --- a/test_requests.py +++ b/test_requests.py @@ -58,6 +58,11 @@ class RequestsTestCase(unittest.TestCase): assert pr.body == 'life=42' + def test_no_content_length(self): + req = requests.Request('GET', httpbin('get')).prepare() + self.assertNotIn('Content-Length', req.headers) + + def test_path_is_not_double_encoded(self): request = requests.Request('GET', "http://0.0.0.0/get/test case").prepare()