Now, Content-Length is only auto-added for non-GET/HEAD requests.
body.seek(0, 0)
elif body is not None:
self.headers['Content-Length'] = str(len(body))
- elif self.method in ('POST', 'PUT', 'PATCH'):
+ elif self.method not in ('GET', 'HEAD'):
self.headers['Content-Length'] = '0'
def prepare_auth(self, auth):
def test_no_content_length(self):
- req = requests.Request('GET', httpbin('get')).prepare()
- self.assertTrue('Content-Length' not in req.headers)
+ get_req = requests.Request('GET', httpbin('get')).prepare()
+ self.assertTrue('Content-Length' not in get_req.headers)
+ head_req = requests.Request('HEAD', httpbin('head')).prepare()
+ self.assertTrue('Content-Length' not in head_req.headers)
def test_path_is_not_double_encoded(self):