Skip to content
Myr

Remove default Content-Length from GET requests.

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

Fix #1051.

authored by Johnny Goodnow · committed by Johnny Goodnow · parent 22623bd · Browse files · 2 files+7 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

2 files+7 added−1 removed

  • other:+7 added−1 removed

2 files+7 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 in ('POST', 'PUT'):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:test_requests.py+5 added
56 unmodified lines
57 assert pr.url == req.url58 assert pr.body == 'life=42'596061 def test_no_content_length(self):62 req = requests.Request('GET', httpbin('get')).prepare()63 self.assertNotIn('Content-Length', req.headers)646566 def test_path_is_not_double_encoded(self):67 request = requests.Request('GET', "http://0.0.0.0/get/test case").prepare()6869 self.assertEqual(request.path_url, "/get/test%20case")
220 unmodified lines