Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip auto-generation of Content-Type header. #507

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Force autogenration of Content-Length header.
Even when the caller asked to skip it!
Marco Paolini committed Sep 14, 2015

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
commit 2ff2f19599f2ee21bdd0803c533b7e3d50977160
3 changes: 1 addition & 2 deletions aiohttp/client_reqrep.py
Original file line number Diff line number Diff line change
@@ -291,8 +291,7 @@ def update_body_from_data(self, data, skip_auto_headers):
if not self.chunked and isinstance(data, io.BytesIO):
# Not chunking if content-length can be determined
size = len(data.getbuffer())
if hdrs.CONTENT_LENGTH not in skip_auto_headers:
self.headers[hdrs.CONTENT_LENGTH] = str(size)
self.headers[hdrs.CONTENT_LENGTH] = str(size)
self.chunked = False
elif not self.chunked and isinstance(data, io.BufferedReader):
# Not chunking if content-length can be determined
10 changes: 9 additions & 1 deletion tests/test_client_request.py
Original file line number Diff line number Diff line change
@@ -259,7 +259,7 @@ def test_content_type_auto_header_get(self):
self.assertNotIn('CONTENT-TYPE', req.headers)

def test_content_type_auto_header_form(self):
req = ClientRequest('get', 'http://python.org', data={'hey': 'you'},
req = ClientRequest('post', 'http://python.org', data={'hey': 'you'},
loop=self.loop)
req.send(self.transport, self.protocol)
self.assertEqual('application/x-www-form-urlencoded',
@@ -285,6 +285,14 @@ def test_content_type_skip_auto_header_form(self):
req.send(self.transport, self.protocol)
self.assertNotIn('CONTENT-TYPE', req.headers)

def test_content_type_auto_header_content_length_no_skip(self):
req = ClientRequest('get', 'http://python.org',
data=io.BytesIO(b'hey'),
skip_auto_headers={'CONTENT-LENGTH'},
loop=self.loop)
req.send(self.transport, self.protocol)
self.assertEqual(req.headers.get('CONTENT-LENGTH'), '3')

def test_path_is_not_double_encoded(self):
req = ClientRequest('get', "http://0.0.0.0/get/test case",
loop=self.loop)