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/

_______________________________________________
Web-SIG mailing list
Web-SIG@python.org
Web SIG: http://www.python.org/sigs/web-sig
Unsubscribe: 
http://mail.python.org/mailman/options/web-sig/archive%40mail-archive.com

Reply via email to