diff --git a/AUTHORS.rst b/AUTHORS.rst index 078ed993..6bbddfde 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -120,3 +120,4 @@ Patches and Suggestions - David Bonner @rascalking - Vinod Chandru - Johnny Goodnow +- Denis Ryzhkov diff --git a/requests/models.py b/requests/models.py index c983db02..fe85a833 100644 --- a/requests/models.py +++ b/requests/models.py @@ -323,6 +323,7 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin): """Prepares the given HTTP headers.""" if headers: + headers = dict((name.encode('ascii'), value) for name, value in headers.items()) self.headers = CaseInsensitiveDict(headers) else: self.headers = CaseInsensitiveDict() diff --git a/test_requests.py b/test_requests.py index 6c4c3dd2..e12722d1 100644 --- a/test_requests.py +++ b/test_requests.py @@ -251,6 +251,9 @@ class RequestsTestCase(unittest.TestCase): requests.get(url, params={'foo': 'foo'}) requests.get(httpbin('ΓΈ'), params={'foo': 'foo'}) + def test_unicode_header_name(self): + requests.put(httpbin('put'), headers={str('Content-Type'): 'application/octet-stream'}, data='\xff') # compat.str is unicode. + def test_urlencoded_get_query_multivalued_param(self): r = requests.get(httpbin('get'), params=dict(test=['foo', 'baz']))