Open
Description
Bug report
When receiving HTTP headers in MIME encoded-word format (per RFC 2047), the http
module does not decode the header's value out of encoded-word. For example:
from http import client
conn = client.HTTPConnection("localhost", 8080)
conn.request("GET", "/")
# the server is configured to return the header X-Star: =?utf-8?b?4piF?=
# which should be the ★ character (U+2605)
resp = conn.getresponse()
print(resp.getheader('X-Star')) # prints "=?utf-8?b?4piF?=", not "★"
Additionally, when setting a header to a string containing a non-ISO-8859-1 character, a UnicodeEncodeError
exception is thrown, however, this could be solved by just using MIME encoded-word. For example:
from http import client
conn = client.HTTPConnection("localhost", 8080)
conn.request("GET", "/", headers={
"X-Star": "★"
})
conn.close() # UnicodeEncodeError: 'latin-1' codec can't encode character '\u2605' in position 0: ordinal not in range(256)
Your environment
- CPython versions tested on: 3.11.3
- Operating system and architecture: macOS 11.7.4, x86_64