[Patches] [ python-Patches-649742 ] urllib2.Request's headers are case-sens.

noreply@sourceforge.net noreply@sourceforge.net
Sun, 08 Dec 2002 09:18:57 -0800


Patches item #649742, was opened at 2002-12-06 21:26
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=649742&group_id=5470

Category: Library (Lib)
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: John J Lee (jjlee)
Assigned to: Nobody/Anonymous (nobody)
Summary: urllib2.Request's headers are case-sens.

Initial Comment:
urllib2.Request's headers are case-sensitive.

This is unfortunate if, for example, you add a content-type header
like so:

req = urllib2.Request("http://blah/", data,
                      headers={"Content-Type": "text/ugly"})

because, while urllib2.AbstractHTTPHandler is careful to check not to
add this header if it's already in the Request, it happens to use a
different case convention:

                if not req.headers.has_key('Content-type'):
                    h.putheader('Content-type',
                                'application/x-www-form-urlencoded')

so you get both headers:

Content-Type: text/ugly
Content-type: application/x-www-form-urlencoded

in essentially random order.  The documentation says:

"""Note that there cannot be more than one header with the same name,
and later calls will overwrite previous calls in case the key
collides.  Currently, this is no loss of functionality, since all
headers which have meaning when used more than once have a
(header-specific) way of gaining the same functionality using only one
header."""

RFC 2616 (section 4.2) says:

"""The order in which header fields with the same field-name are
received is therefore significant to the interpretation of the
combined field value, and thus a proxy MUST NOT change the order of
these field values when a message is forwarded."""

The patch fixes this by adding normalisation of header case to
urllib.Request.  With the patch, you'd get:

Content-type: text/ugly


John


----------------------------------------------------------------------

>Comment By: John J Lee (jjlee)
Date: 2002-12-08 17:18

Message:
Logged In: YES 
user_id=261020

Here it is.

I swear I did check the box.  I clicked the button twice, though --
I guess SF doesn't like that.


John


----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2002-12-07 08:43

Message:
Logged In: YES 
user_id=21627

There's no uploaded file!  You have to check the
checkbox labeled "Check to Upload & Attach File"
when you upload a file.

Please try again.

(This is a SourceForge annoyance that we can do
nothing about. :-( )

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=649742&group_id=5470