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

Armin Ronacher armin.ronacher at active-4.com
Tue Sep 22 10:11:57 CEST 2009


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.

> 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.


Regards,
Armin


More information about the Web-SIG mailing list