Urllib3 will fill in the content-length automatically

This commit is contained in:
Honza Král
2014-10-01 16:14:27 +02:00
parent 45a4d36ae1
commit 20aa35d791
2 changed files with 1 additions and 12 deletions
+1 -4
View File
@@ -40,10 +40,7 @@ class Urllib3HttpConnection(Connection):
kw = {}
if timeout:
kw['timeout'] = timeout
headers = self.headers.copy()
if body:
headers['content-length'] = str(len(body))
response = self.pool.urlopen(method, url, body, retries=False, headers=headers, **kw)
response = self.pool.urlopen(method, url, body, retries=False, headers=self.headers, **kw)
duration = time.time() - start
raw_data = response.data.decode('utf-8')
except Exception as e:
-8
View File
@@ -53,14 +53,6 @@ class TestUrllib3Connection(TestCase):
con = Urllib3HttpConnection()
self.assertIsInstance(con.pool, urllib3.HTTPConnectionPool)
def test_content_length_gets_set(self):
con = Urllib3HttpConnection()
m = con.pool.urlopen = Mock()
m.return_value.status = 200
con.perform_request('PUT', '/', body='0123456789'.encode('utf-8'))
m.assert_called_once_with('PUT', '/', '0123456789'.encode('utf-8'), headers={'content-length': '10'}, retries=False)
class TestRequestsConnection(TestCase):
def _get_mock_connection(self, connection_params={}, status_code=200, response_body='{}'):
con = RequestsHttpConnection(**connection_params)