summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGian Ortiz <brksgian@gmail.com>2021-01-13 17:45:56 -0300
committerGitHub <noreply@github.com>2021-01-13 21:45:56 +0100
commitdb685d58b5456b5ac15e02ddc5b3e2d2f81a197b (patch)
tree6bf844dcee54a2d0add41bd8bf3147d764fd11c6
parent44ae67685d1eb184071899c9e0b7a0dd5d5cb9a5 (diff)
Decode headers using utf-8 only if they are not str (#1020)
-rw-r--r--httpie/sessions.py4
-rw-r--r--tests/test_sessions.py7
2 files changed, 10 insertions, 1 deletions
diff --git a/httpie/sessions.py b/httpie/sessions.py
index 5a4acef8..cc54def6 100644
--- a/httpie/sessions.py
+++ b/httpie/sessions.py
@@ -77,7 +77,9 @@ class Session(BaseConfigDict):
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
diff --git a/tests/test_sessions.py b/tests/test_sessions.py
index 4fbc0031..ea22a1ad 100644
--- a/tests/test_sessions.py
+++ b/tests/test_sessions.py
@@ -16,6 +16,7 @@ from httpie.sessions import Session
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:
@@ -161,6 +162,12 @@ class TestSession(SessionTestBase):
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'