Skip to content
Myr

Merge pull request #1142 from theaeolianmachine/removeGETContentLength

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

Remove default Content-Length from GET requests.

authored by Kenneth Reitz · committed by Kenneth Reitz · parents 22623bd, 8d8865a · Browse files · 3 files+10 added−1 removed
This commit

State

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

Diff stats

3 files+10 added−1 removed

  • other:+10 added−1 removed

3 files+10 added−1 removed

modified:requests/models.py+2 added-1 removed
384 unmodified lines
385386 self.body = body387388 def prepare_content_length(self, body):389 self.headers['Content-Length'] = '0'389 if hasattr(body, 'seek') and hasattr(body, 'tell'):390 body.seek(0, 2)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 not in ('GET', 'HEAD'):396 self.headers['Content-Length'] = '0'397398 def prepare_auth(self, auth):399 """Prepares the given HTTP auth data."""400 if auth:
258 unmodified lines
modified:AUTHORS.rst+1 added
117 unmodified lines
118- Martijn Pieters119- Jonatan Heyman120- David Bonner <dbonner@gmail.com> @rascalking121- Vinod Chandru122- Johnny Goodnow <j.goodnow29@gmail.com>
modified:test_requests.py+7 added
56 unmodified lines
57 assert pr.url == req.url58 assert pr.body == 'life=42'596061 def test_no_content_length(self):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()7071 self.assertEqual(request.path_url, "/get/test%20case")
220 unmodified lines