Skip to content
Myr

Merge pull request #2332 from asnelzin/fix-2329

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

Add overriding Content-Length

authored by Kenneth Reitz · committed by Kenneth Reitz · parents e4ddca0, ee50afe · Browse files · 2 files+9 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+9 added−1 removed

  • other:+9 added−1 removed

2 files+9 added−1 removed

modified:requests/models.py+1 added-1 removed
470 unmodified lines
471 elif body is not None:472 l = super_len(body)473 if l:474 self.headers['Content-Length'] = builtin_str(l)475 elif self.method not in ('GET', 'HEAD'):475 elif (self.method not in ('GET', 'HEAD')) and (self.headers.get('Content-Length') is None):476 self.headers['Content-Length'] = '0'477478 def prepare_auth(self, auth, url=''):479 """Prepares the given HTTP auth data."""
358 unmodified lines
modified:test_requests.py+8 added
101 unmodified lines
102 assert 'Content-Length' not in get_req.headers103 head_req = requests.Request('HEAD', httpbin('head')).prepare()104 assert 'Content-Length' not in head_req.headers105106 def test_override_content_length(self):107 headers = {108 'Content-Length': 'not zero'109 }110 r = requests.Request('POST', httpbin('post'), headers=headers).prepare()111 assert 'Content-Length' in r.headers112 assert r.headers['Content-Length'] == 'not zero'113114 def test_path_is_not_double_encoded(self):115 request = requests.Request('GET', "http://0.0.0.0/get/test case").prepare()116117 assert request.path_url == '/get/test%20case'
1416 unmodified lines