httppeer: allow extensions to replace urllib2.Request
The authentication library my extension wants to use requires using a different
opener and a different request builder. This change pulls the call to
urllib2.Request out so that my extension can replace it just like it can
replace urlopener.
--- a/mercurial/httppeer.py Sun Jun 07 17:50:56 2015 -0700
+++ b/mercurial/httppeer.py Mon Jun 08 16:55:21 2015 -0700
@@ -30,6 +30,7 @@
self.caps = None
self.handler = None
self.urlopener = None
+ self.requestbuilder = None
u = util.url(path)
if u.query or u.fragment:
raise util.Abort(_('unsupported URL component: "%s"') %
@@ -42,6 +43,7 @@
self.ui.debug('using %s\n' % self._url)
self.urlopener = url.opener(ui, authinfo)
+ self.requestbuilder = urllib2.Request
def __del__(self):
if self.urlopener:
@@ -111,7 +113,7 @@
q += sorted(args.items())
qs = '?%s' % urllib.urlencode(q)
cu = "%s%s" % (self._url, qs)
- req = urllib2.Request(cu, data, headers)
+ req = self.requestbuilder(cu, data, headers)
if data is not None:
self.ui.debug("sending %s bytes\n" % size)
req.add_unredirected_header('Content-Length', '%d' % size)