[Web-SIG] Request for Comments on upcoming WSGI Changes

Mark Nottingham mnot at mnot.net
Tue Sep 22 10:16:07 CEST 2009


On 22/09/2009, at 6:11 PM, Armin Ronacher wrote:

> Hi,
>
> Mark Nottingham schrieb:
>> HTTP headers *are* ASCII; RFC2616 defined them to be ISO-8859-1, but
>> HTTPbis currently takes the stance that they're ASCII, as in practice
>> Latin-1 isn't used and may introduce interop problems.
> In practise non-ascii data ends up in headers.

Yes. However, it shouldn't be encouraged.

>
>> What does it mean to "support non-ASCII headers"? As per above, the
>> only sane thing to do is treat them as opaque data, because you can't
>> be certain of their encoding unless you have knowledge of the header.
> Here what http.server does in Python 3 (actual code):
>
>    def send_header(self, keyword, value):
>        """Send a MIME header."""
>        if self.request_version != 'HTTP/0.9':
>            self.wfile.write(("%s: %s\r\n" % (keyword,
>                      value)).encode('ASCII', 'strict'))
>
>        if keyword.lower() == 'connection':
>            if value.lower() == 'close':
>                self.close_connection = 1
>            elif value.lower() == 'keep-alive':
>                self.close_connection = 0
>
> So it will give you a nice UnicodeEncodeError if you try to send
> anything outside of the ASCII range as header.


Ouch.


--
Mark Nottingham     http://www.mnot.net/



More information about the Web-SIG mailing list