From 089e82993c8393453fa74b8a3ba6f0dd4240f8a0 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Thu, 26 Mar 2015 18:43:12 -0700 Subject: [PATCH] Set default Content-Type for post requests #184 --- CHANGES.txt | 4 +++- aiohttp/client.py | 5 +++++ tests/test_client_functional.py | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index 86fd0454dbb..d4ce9fda154 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -4,12 +4,14 @@ CHANGES 0.15.0 (Unreleased) ------------------- -- Client WebSockets support. +- Client WebSockets support - New Multipart system #273 - Support for "Except" header #287 #267 +- Set default Content-Type for post requests #184 + - Fix issue with construction dynamic route with regexps and trailing slash #266 - Add repr to web.Request diff --git a/aiohttp/client.py b/aiohttp/client.py index 730f21fa2c4..4b280b76417 100644 --- a/aiohttp/client.py +++ b/aiohttp/client.py @@ -548,6 +548,11 @@ def send(self, writer, reader): request.enable_chunked_encoding() request.add_chunking_filter(self.chunked) + # set default content-type + if (self.method in self.POST_METHODS and + hdrs.CONTENT_TYPE not in self.headers): + self.headers[hdrs.CONTENT_TYPE] = 'application/octet-stream' + request.add_headers( *((k, v) for k, v in ((k, value) diff --git a/tests/test_client_functional.py b/tests/test_client_functional.py index d49e98ff3ce..595c062d52f 100644 --- a/tests/test_client_functional.py +++ b/tests/test_client_functional.py @@ -686,6 +686,8 @@ def stream(): self.assertEqual(str(len(data)), content['headers']['Content-Length']) + self.assertEqual('application/octet-stream', + content['headers']['Content-Type']) def test_POST_StreamReader(self): with test_utils.run_server(self.loop, router=Functional) as httpd: