Skip to content
Myr

Remove Content-Length from GET/HEAD by default.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Now, Content-Length is only auto-added for non-GET/HEAD requests.

authored by Johnny Goodnow · committed by Johnny Goodnow · parent f7c10ca · Browse files · 2 files+5 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+5 added−3 removed

  • other:+5 added−3 removed

2 files+5 added−3 removed

modified:requests/models.py+1 added-1 removed
390 unmodified lines
391 self.headers['Content-Length'] = str(body.tell())392 body.seek(0, 0)393 elif body is not None:394 self.headers['Content-Length'] = str(len(body))395 elif self.method in ('POST', 'PUT', 'PATCH'):395 elif self.method not in ('GET', 'HEAD'):396 self.headers['Content-Length'] = '0'397398 def prepare_auth(self, auth):399 """Prepares the given HTTP auth data."""
259 unmodified lines
modified:test_requests.py+4 added-2 removed
57 unmodified lines
58 assert pr.body == 'life=42'596061 def test_no_content_length(self):62 req = requests.Request('GET', httpbin('get')).prepare()63 self.assertTrue('Content-Length' not in req.headers)62 get_req = requests.Request('GET', httpbin('get')).prepare()63 self.assertTrue('Content-Length' not in get_req.headers)64 head_req = requests.Request('HEAD', httpbin('head')).prepare()65 self.assertTrue('Content-Length' not in head_req.headers)666768 def test_path_is_not_double_encoded(self):69 request = requests.Request('GET', "http://0.0.0.0/get/test case").prepare()
222 unmodified lines