]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
When setting headers, fallback to `utf-8` if no encoding is specified yet. (#820)
authorPiotr Staroszczyk <piotr.staroszczyk@get24.org>
Mon, 24 Feb 2020 12:29:51 +0000 (13:29 +0100)
committerGitHub <noreply@github.com>
Mon, 24 Feb 2020 12:29:51 +0000 (12:29 +0000)
* Headers: fallback to utf8 encoding

* Headers.__setitem__: use utf8 only if encoding is not set

httpx/_models.py

index 861e85fab6cd9b5604ad608b21e4b668784e408b..2bfa367ab911d4120364a2b733bf5c4885710951 100644 (file)
@@ -515,8 +515,8 @@ class Headers(typing.MutableMapping[str, str]):
         Set the header `key` to `value`, removing any duplicate entries.
         Retains insertion order.
         """
-        set_key = key.lower().encode(self.encoding)
-        set_value = value.encode(self.encoding)
+        set_key = key.lower().encode(self._encoding or "utf-8")
+        set_value = value.encode(self._encoding or "utf-8")
 
         found_indexes = []
         for idx, (item_key, _) in enumerate(self._list):