mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
Merge pull request #1142 from theaeolianmachine/removeGETContentLength
Remove default Content-Length from GET requests.
This commit is contained in:
@@ -119,3 +119,4 @@ Patches and Suggestions
|
||||
- Jonatan Heyman
|
||||
- David Bonner <dbonner@gmail.com> @rascalking
|
||||
- Vinod Chandru
|
||||
- Johnny Goodnow <j.goodnow29@gmail.com>
|
||||
|
||||
+2
-1
@@ -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 not in ('GET', 'HEAD'):
|
||||
self.headers['Content-Length'] = '0'
|
||||
|
||||
def prepare_auth(self, auth):
|
||||
"""Prepares the given HTTP auth data."""
|
||||
|
||||
@@ -58,6 +58,13 @@ class RequestsTestCase(unittest.TestCase):
|
||||
assert pr.body == 'life=42'
|
||||
|
||||
|
||||
def test_no_content_length(self):
|
||||
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):
|
||||
request = requests.Request('GET', "http://0.0.0.0/get/test case").prepare()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user