Mercurial > hg
changeset 37547:835ccc2a5ef1
httppeer: move requestbuilder defaults into makepeer() argument
Upcoming commits will move the initial ?cmd=capabilities handshake
request out of httppeer so the handshake can be performed before a
peer instance is constructed. In order to do this, we'll need to
refactor code for making HTTP requests.
The type used to construct HTTP requests is configurable. If we'll
be making HTTP requests outside of httppeer, we should be able to
use a custom request builder. So move the definition of that type
into makepeer().
Extensions can monkeypatch the function and override the argument
value.
Differential Revision: https://phab.mercurial-scm.org/D3232
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Tue, 10 Apr 2018 10:22:26 -0700 |
parents | 3a2367e6c6f2 |
children | 8e7a4435ab6d |
files | mercurial/debugcommands.py mercurial/httppeer.py tests/test-check-interfaces.py |
diffstat | 3 files changed, 13 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/debugcommands.py Mon Apr 09 19:35:39 2018 -0700 +++ b/mercurial/debugcommands.py Tue Apr 10 10:22:26 2018 -0700 @@ -2915,7 +2915,8 @@ raise error.Abort(_('--peer %s not supported with HTTP peers') % opts['peer']) else: - peer = httppeer.httppeer(ui, path, url, opener) + peer = httppeer.httppeer(ui, path, url, opener, + requestbuilder=httppeer.urlreq.request) peer._fetchcaps() # We /could/ populate stdin/stdout with sock.makefile()...
--- a/mercurial/httppeer.py Mon Apr 09 19:35:39 2018 -0700 +++ b/mercurial/httppeer.py Tue Apr 10 10:22:26 2018 -0700 @@ -139,15 +139,13 @@ self._index = 0 class httppeer(wireproto.wirepeer): - def __init__(self, ui, path, url, opener): + def __init__(self, ui, path, url, opener, requestbuilder): self.ui = ui self._path = path self._url = url self._caps = None self._urlopener = opener - # This is an its own attribute to facilitate extensions overriding - # the default type. - self._requestbuilder = urlreq.request + self._requestbuilder = requestbuilder def __del__(self): for h in self._urlopener.handlers: @@ -570,7 +568,12 @@ return results -def makepeer(ui, path): +def makepeer(ui, path, requestbuilder=urlreq.request): + """Construct an appropriate HTTP peer instance. + + ``requestbuilder`` is the type used for constructing HTTP requests. + It exists as an argument so extensions can override the default. + """ u = util.url(path) if u.query or u.fragment: raise error.Abort(_('unsupported URL component: "%s"') % @@ -582,7 +585,7 @@ opener = urlmod.opener(ui, authinfo) - return httppeer(ui, path, url, opener) + return httppeer(ui, path, url, opener, requestbuilder) def instance(ui, path, create): if create:
--- a/tests/test-check-interfaces.py Mon Apr 09 19:35:39 2018 -0700 +++ b/tests/test-check-interfaces.py Tue Apr 10 10:22:26 2018 -0700 @@ -70,7 +70,7 @@ # Facilitates testing sshpeer without requiring an SSH server. class badpeer(httppeer.httppeer): def __init__(self): - super(badpeer, self).__init__(None, None, None, dummyopener()) + super(badpeer, self).__init__(None, None, None, dummyopener(), None) self.badattribute = True def badmethod(self): @@ -89,7 +89,7 @@ ziverify.verifyClass(repository.ipeerbaselegacycommands, httppeer.httppeer) - checkzobject(httppeer.httppeer(None, None, None, dummyopener())) + checkzobject(httppeer.httppeer(None, None, None, dummyopener(), None)) ziverify.verifyClass(repository.ipeerbase, localrepo.localpeer)