New submission from Cal Leeming cal.leem...@simplicitymedialtd.co.uk:
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
R. David Murray rdmur...@bitdance.com added the comment:
Well, three occurrences means you only have three methods to patch (and two of
them are trivial). But I agree that copying the non-trivial method doesn't
look fun from a maintenance perspective.
You could also try using an object that
Cal Leeming cal.leem...@simplicitymedialtd.co.uk added the comment:
Sorry, I should clarify.. The str() patch worked, but it failed to work within
the realm of urllib2:
s = _str(Content-MD5)
print Builtin:
print plain: %s % ( s )
print capitalized: %s % ( s.capitalize() )
s =
R. David Murray rdmur...@bitdance.com added the comment:
Well, judging by your test it isn't capitalize that's the issue. capitalize
produces Content-md5, whereas debug is showing urllib2 sending Content-Md5. So
something else is massaging the header name on send.
--
Cal Leeming cal.leem...@simplicitymedialtd.co.uk added the comment:
(short answer, I found the cause, and a suitable monkey patch) - below are
details of how I did it and steps I took.
-
Okay so I forked AbstractHTTPHandler() then patched do_request_(), at which
point request.headers and
Cal Leeming cal.leem...@simplicitymedialtd.co.uk added the comment:
So @r.david.murray, it would appear you were right :D Really, I should have
looped through each method on str(), and wrapped them all to see which were
being called, but lesson learned I guess.
Sooo, I guess now the question