diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index b92847f8..8a908227 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -13,6 +13,7 @@ This project adheres to `Semantic Versioning `_.
an alternative to ``stdin``. (`#534`_)
* Fixed ``--continue --download`` with a single byte to be downloaded left. (`#1032`_)
* Fixed ``--verbose`` HTTP 307 redirects with streamed request body. (`#1088`_)
+* Fixed handling of session files with `Cookie:` followed by other headers. (`#1126`_)
* Add internal support for file-like object responses to improve adapter plugin support. (`#1094`_)
diff --git a/httpie/sessions.py b/httpie/sessions.py
index 0d800c0f..2876935a 100644
--- a/httpie/sessions.py
+++ b/httpie/sessions.py
@@ -72,7 +72,7 @@ class Session(BaseConfigDict):
"""
headers = self.headers
- for name, value in request_headers.items():
+ for name, value in request_headers.copy().items():
if value is None:
continue # Ignore explicitly unset headers
diff --git a/tests/test_sessions.py b/tests/test_sessions.py
index 23e1dd9c..3568382d 100644
--- a/tests/test_sessions.py
+++ b/tests/test_sessions.py
@@ -178,6 +178,24 @@ class TestSession(SessionTestBase):
assert HTTP_OK in r2
assert r2.json['headers']['Foo'] == 'Bar'
+ def test_session_with_cookie_followed_by_another_header(self, httpbin):
+ """
+ Make sure headers don’t get mutated —
+ """
+ self.start_session(httpbin)
+ session_data = {
+ "headers": {
+ "cookie": "...",
+ "zzz": "..."
+ }
+ }
+ session_path = self.config_dir / 'session-data.json'
+ session_path.write_text(json.dumps(session_data))
+ r = http('--session', str(session_path), 'GET', httpbin.url + '/get',
+ env=self.env())
+ assert HTTP_OK in r
+ assert 'Zzz' in r
+
def test_session_unicode(self, httpbin):
self.start_session(httpbin)