[issue17322] urllib.request add_header() currently allows trailing spaces (and other weird stuff)

karl report at bugs.python.org
Mon Mar 4 15:48:02 CET 2013


karl added the comment:

R. David.:
> A crazy idea that occurred to me was to create an "rfc822-style-header management" module, and share it between email, http, and urllib.

Yes it is basically what I had in mind when I said:

>Maybe the way forward in the future is to have a header factory shared by all HTTP libs?

I'm not sure if it's easy to share in between emails and HTTP. Emails are now defined by RFC5322:
https://tools.ietf.org/html/rfc5322#section-2.2

2.2. Header Fields


   Header fields are lines beginning with a field name, followed by a
   colon (":"), followed by a field body, and terminated by CRLF.  A
   field name MUST be composed of printable US-ASCII characters (i.e.,
   characters that have values between 33 and 126, inclusive), except
   colon.  A field body may be composed of printable US-ASCII characters
   as well as the space (SP, ASCII value 32) and horizontal tab (HTAB,
   ASCII value 9) characters (together known as the white space
   characters, WSP).  A field body MUST NOT include CR and LF except
   when used in "folding" and "unfolding", as described in section
   2.2.3.  All field bodies MUST conform to the syntax described in
   sections 3 and 4 of this specification.

Maybe it's doable and worth exploring but I have the feeling we would end up with something along

field-name ":" field-value

and all the rules for field-name and field-value being different for HTTP and email, because they really are. Folding, set of characters, etc. :)

Another thing which should be also the opportunity for opening another issue. HTTP headers and python dictionaries is not a very good match. :) But this is drifting off-topic. :)

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue17322>
_______________________________________


More information about the Python-bugs-list mailing list