diff --git a/httpie/sessions.py b/httpie/sessions.py index e61a8e3e..32254bfb 100644 --- a/httpie/sessions.py +++ b/httpie/sessions.py @@ -101,6 +101,10 @@ class Session(BaseConfigDict): """ for name, value in request_headers.items(): + + if value is None: + continue # Ignore explicitely unset headers + value = value.decode('utf8') if name == 'User-Agent' and value.startswith('HTTPie/'): continue diff --git a/tests/test_sessions.py b/tests/test_sessions.py index 966d87b4..f5683774 100644 --- a/tests/test_sessions.py +++ b/tests/test_sessions.py @@ -2,6 +2,7 @@ import os import shutil import sys +from tempfile import gettempdir import pytest @@ -174,3 +175,14 @@ class TestSession(SessionTestBase): r2 = http('--session=test', httpbin.url + '/headers', env=self.env()) assert HTTP_OK in r2 assert r2.json['headers']['User-Agent'] == 'custom' + + def test_download_in_session(self, httpbin): + # https://github.com/jkbrzt/httpie/issues/412 + self.start_session(httpbin) + cwd = os.getcwd() + try: + os.chdir(gettempdir()) + http('--session=test', '--download', + httpbin.url + '/get', env=self.env()) + finally: + os.chdir(cwd)