Issue 812285: More precise realm parsing in AbstractBasicAuthHandler (original) (raw)

AbstractBasicAuthHandler class parses headers to search for a scheme and its realm.

"rx" is the compiled regular expression that is used to match these items. But it doesn't work on multiple auth-schemes (as stated in urllib2.py source code). Since I HAD to work around this issue (we have NTLM authentication first in our proxy) I managed a bit the regular expression (rx) and its groups.

The auth-request I had to face is:
< NTLM, Basic realm="something" >, so I created a RE with named groups to find exactly the type of request that has a "realm" after the scheme, and that can contain commas, in this way: < ([ \t]+|(.,)+)*(?P[^ \t]+)[ \t]+realm="(?P[^"])"' >

Matching groups "scheme" and "realm" will contain right values as parsed.

This will NOT fix issue with multiple realm-based requests (it will return only last one), but seems to handle well requests like the one specified.

Diff attached for Python 2.3

Hope this helps,

Federico Di Carlo