From: Piotr Staroszczyk Date: Mon, 24 Feb 2020 12:29:51 +0000 (+0100) Subject: When setting headers, fallback to `utf-8` if no encoding is specified yet. (#820) X-Git-Tag: 0.12.0~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=50d337e807839c21e796fd8b01c67d8a672a9721;p=thirdparty%2Fhttpx.git When setting headers, fallback to `utf-8` if no encoding is specified yet. (#820) * Headers: fallback to utf8 encoding * Headers.__setitem__: use utf8 only if encoding is not set --- diff --git a/httpx/_models.py b/httpx/_models.py index 861e85fa..2bfa367a 100644 --- a/httpx/_models.py +++ b/httpx/_models.py @@ -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):