Skip to content
Myr

Use builtin_str for all auto-set header values.

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

authored by Cory Benfield · committed by Cory Benfield · parent e91ee0e · Browse files · 2 files+11 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+11 added−3 removed

  • other:+11 added−3 removed

2 files+11 added−3 removed

modified:requests/models.py+3 added-3 removed
405 unmodified lines
406 if files:407 raise NotImplementedError('Streamed bodies and files are mutually exclusive.')408409 if length is not None:410 self.headers['Content-Length'] = str(length)410 self.headers['Content-Length'] = builtin_str(length)411 else:412 self.headers['Transfer-Encoding'] = 'chunked'413 else:414 # Multi-part file uploads.
17 unmodified lines
432433 def prepare_content_length(self, body):434 if hasattr(body, 'seek') and hasattr(body, 'tell'):435 body.seek(0, 2)436 self.headers['Content-Length'] = str(body.tell())436 self.headers['Content-Length'] = builtin_str(body.tell())437 body.seek(0, 0)438 elif body is not None:439 l = super_len(body)440 if l:441 self.headers['Content-Length'] = str(l)441 self.headers['Content-Length'] = builtin_str(l)442 elif self.method not in ('GET', 'HEAD'):443 self.headers['Content-Length'] = '0'444445 def prepare_auth(self, auth, url=''):
288 unmodified lines
modified:test_requests.py+8 added
682 unmodified lines
683 p = r.prepare()684685 self.assertTrue('multipart/form-data' in p.headers['Content-Type'])686687 def test_autoset_header_values_are_native(self):688 data = 'this is a string'689 length = '16'690 req = requests.Request('POST', httpbin('post'), data=data)691 p = req.prepare()692693 self.assertEqual(p.headers['Content-Length'], length)694695696class TestContentEncodingDetection(unittest.TestCase):697698 def test_none(self):699 encodings = requests.utils.get_encodings_from_content('')
207 unmodified lines