Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decode headers using utf-8 only if they are not str #1020

Merged
merged 1 commit into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion httpie/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ def update_headers(self, request_headers: RequestHeadersDict):
if value is None:
continue # Ignore explicitly unset headers

value = value.decode('utf8')
if type(value) is not str:
value = value.decode('utf8')

if name.lower() == 'user-agent' and value.startswith('HTTPie/'):
continue

Expand Down
7 changes: 7 additions & 0 deletions tests/test_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from httpie.utils import get_expired_cookies
from tests.test_auth_plugins import basic_auth
from utils import HTTP_OK, MockEnvironment, http, mk_config_dir
from fixtures import FILE_PATH_ARG


class SessionTestBase:
Expand Down Expand Up @@ -161,6 +162,12 @@ def test_session_ignored_header_prefixes(self, httpbin):
assert 'Content-Type' not in r2.json['headers']
assert 'If-Unmodified-Since' not in r2.json['headers']

def test_session_with_upload(self, httpbin):
self.start_session(httpbin)
r = http('--session=test', '--form', '--verbose', 'POST', httpbin.url + '/post',
f'test-file@{FILE_PATH_ARG}', 'foo=bar', env=self.env())
assert HTTP_OK in r

def test_session_by_path(self, httpbin):
self.start_session(httpbin)
session_path = self.config_dir / 'session-by-path.json'
Expand Down