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 Cal.Leeming
Recipients Cal.Leeming
Date 2011-06-30.19:23:37
SpamBayes Score 4.7457616e-09
Marked as misclassified No
Message-id <1309461818.92.0.299415077626.issue12455@psf.upfronthosting.co.za>
In-reply-to
Content
I came up against a problem today whilst trying to submit a request to a remote API. The header needed to contain:

'Content-MD5' : "md5here"

But the urllib2 Request() forces capitalize() on all header names, and transformed it into "Content-Md5", which in turn made the remote web server ignore the header and break the request (as the remote side is case sensitive, of which we don't have any control over).

I attempted to get smart by using the following patch:
class _str(str):
    def capitalize(s):
        print s
        return s

_headers = {_str("Content-MD5") : 'md5here'}

But this failed to work:


---HEADERS---
{'Content-MD5': 'nts0yj7AdzJALyNOxafDyA=='}

---URLLIB2 DEBUG---
send: 'POST /api/v1 m HTTP/1.1\r\nContent-Md5: nts0yj7AdzJALyNOxafDyA==\r\n\r\n\r\n'

Upon inspecting the urllib2.py source, I found 3 references to capitalize() which seem to cause this problem, but it seems impossible to monkey patch, nor fix without forking.

Therefore, I'd like to +1 a feature request to have an extra option at the time of the request being opened, to bypass the capitalize() on header names (maybe, header_keep_original = True or something). 

And, if anyone could suggest a possible monkey patch (which doesn't involve forking huge chunks of code), that'd be good too :)

Thanks

Cal
History
Date User Action Args
2011-06-30 19:23:38Cal.Leemingsetrecipients: + Cal.Leeming
2011-06-30 19:23:38Cal.Leemingsetmessageid: <1309461818.92.0.299415077626.issue12455@psf.upfronthosting.co.za>
2011-06-30 19:23:38Cal.Leeminglinkissue12455 messages
2011-06-30 19:23:37Cal.Leemingcreate