diff --git a/tests/test_core.py b/tests/test_core.py index df20660..5b8a374 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -277,6 +277,17 @@ class TwythonAPITestCase(unittest.TestCase): """Test attempting to get a header when no API call was made raises a TwythonError""" self.assertRaises(TwythonError, self.api.get_lastfunction_header, 'no-api-call-was-made') + @responses.activate + def test_sends_correct_accept_encoding_header(self): + """Test that Twython accepts compressed data.""" + endpoint = 'statuses/home_timeline' + url = self.get_url(endpoint) + self.register_response(responses.GET, url) + + self.api.get(endpoint) + + self.assertEqual(b'gzip, deflate, compress', responses.calls[0].request.headers['Accept-Encoding']) + # Static methods def test_construct_api_url(self): """Test constructing a Twitter API url works as we expect""" diff --git a/twython/api.py b/twython/api.py index db79381..88b6735 100644 --- a/twython/api.py +++ b/twython/api.py @@ -109,10 +109,14 @@ class Twython(EndpointsMixin, object): # Never be used again. client_args_copy = self.client_args.copy() for k, v in client_args_copy.items(): - if k in ('cert', 'headers', 'hooks', 'max_redirects', 'proxies'): + if k in ('cert', 'hooks', 'max_redirects', 'proxies'): setattr(self.client, k, v) self.client_args.pop(k) # Pop, pop! + # Headers are always present, so we unconditionally pop them and merge + # them into the session headers. + self.client.headers.update(self.client_args.pop('headers')) + self._last_call = None def __repr__(self):