This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author frispete
Recipients frispete
Date 2008-03-11.21:22:16
SpamBayes Score 0.56787485
Marked as misclassified No
Message-id <1205270540.47.0.336665756101.issue2275@psf.upfronthosting.co.za>
In-reply-to
Content
The urllib2 behavior related to headers is - hmm - improvable. 
It simply capitalize() the key, which leads to funny results like:
Accept-charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
while this is seemingly conforming to the specs, it's simply different 
to every other implementation of such things.. 

And we can do better. How about:
--- /usr/lib/python/urllib2.py  2008-01-10 19:03:55.000000000 +0100
+++ urllib2.py  2008-03-11 21:25:33.523890670 +0100
@@ -261,13 +261,16 @@ class Request:
     def is_unverifiable(self):
         return self.unverifiable

+    def _cap_header_key(self, key):
+        return '-'.join((ck.capitalize() for ck in key.split('-')))
+
     def add_header(self, key, val):
         # useful for something like authentication
-        self.headers[key.capitalize()] = val
+        self.headers[self._cap_header_key(key)] = val

     def add_unredirected_header(self, key, val):
         # will not be added to a redirected request
-        self.unredirected_hdrs[key.capitalize()] = val
+        self.unredirected_hdrs[self._cap_header_key(key)] = val

     def has_header(self, header_name):
         return (header_name in self.headers or

I'm not happy with the _cap_header_key name, but you get the idea.
The patch is optimized to operate with maximum locality. It's also 
attached.

I would be very grateful, if something similar could be applied.

Opinions?
History
Date User Action Args
2008-03-11 21:22:20frispetesetspambayes_score: 0.567875 -> 0.56787485
recipients: + frispete
2008-03-11 21:22:20frispetesetspambayes_score: 0.567875 -> 0.567875
messageid: <1205270540.47.0.336665756101.issue2275@psf.upfronthosting.co.za>
2008-03-11 21:22:19frispetelinkissue2275 messages
2008-03-11 21:22:18frispetecreate