Fix handling of session files with Cookie: followed by other headers (#1127)

* Fix the handling of cookies from session files

* Apply suggestions from code review

Co-authored-by: Jakub Roztocil <jakub@roztocil.co>

* Fix test docstring formatting

Co-authored-by: Jakub Roztocil <jakub@roztocil.co>
This commit is contained in:
Mickaël Schoentgen 2021-08-16 14:50:46 +02:00 committed by GitHub
parent 54c8612452
commit d7caeaf372
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 1 deletions

View File

@ -13,6 +13,7 @@ This project adheres to `Semantic Versioning <https://semver.org/>`_.
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`_)

View File

@ -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

View File

@ -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 dont get mutated <https://github.com/httpie/httpie/issues/1126>
"""
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)