using HTTP Digest auth with arbitrary HTTP methods?
John J. Lee
jjl at pobox.com
Mon Jan 3 13:11:06 EST 2005
John Reese <jtr at ofb.net> writes:
> In comp.lang.python, [I] wrote:
> I instead copied it (to urllib3.py) and made the following changes:
> a. in AbstractDigestAuthHandler.get_authorization, call
> req.get_method() instead of req.has_data() and 'POST' or 'GET'
> (python has a ternary operator, who knew)
(Re ternary operator: Everybody who read this list at certain times in
the past is painfully aware of that fact, and of precisely why it's
not quite true, and of all the syntax alternatives for real ternary
conditionals that will never be part of Python ;-)
> b. in AbstractHTTPHandler.do_open, call req.get_method instead of the
> hard-coded if-logic which is the same as that in req.get_method
> Both of these seem like bugs in urllib2.
Yup, bugs both.
> Then I overrode urllib2.Request and made it possibly to set the method,
> and then passed an instance of my custom Request class (the one that
> shouldn't have to exist, since Request should allow method to be set
> explicitly) to OpenerDirector.open().
> I'd like to see these changes make it into the standard library -- after
> being vetted by whoever's in charge of urllib2. Anybody know who I
> should talk to?
Nobody is really in charge: just go ahead and submit a patch. Drop me
an email when you do, and I'll try to review it. The only reason
urllib2 doesn't already do arbitrary HTTP methods is that nobody has
spent the time to think carefully if a .set_method() really is the
right way to do it, then followed through with the work needed to get
a patch applied.
As always, a precondition for change is that somebody thinks something
through carefully, writes tests, documentation, patch and submits all
three to the SF patch tracker with a brief explanation like the one
you give above.
BTW, Greg Stein started work on adding the stuff you need at the
httplib level (as module httpx). He seems too busy to finish it, but
see modules httpx and davlib (one or both are in the Python CVS
sandbox). He thinks httplib is a better place for DAV than urllib2,
and he should know. But go ahead and fix urllib2 anyway... :-)
More information about the Python-list