This is an archive of the discontinued Mercurial Phabricator instance.

wireprotov2: client support for following content redirects
ClosedPublic

Authored by indygreg on Sep 26 2018, 9:09 PM.

Details

Summary

And with the server actually sending content redirects, it is finally
time to implement client support for following them!

When a redirect response is seen, we wait until all data for that
request has been received (it should be nearly immediate since no
data is expected to follow the redirect message). Then we use
a URL opener to make a request. We stuff that response into the
client handler and construct a new response object to track it.

When readdata() is called for servicing requests, we attempt to
read data from the first redirected response. During data reading,
data is processed similarly to as if it came from a frame payload.

The existing test for the functionality demonstrates the client
transparently following the redirect and obtaining the command
response data from an alternate URL!

There is still plenty of work to do here, including shoring up
testing. I'm not convinced things will work in the presence of
multiple redirect responses. And we don't yet implement support
for integrity verification or configuring server certificates
to validate the connection. But it's a start. And it should enable
us to start experimenting with "real" caches.

Diff Detail

Repository
rHG Mercurial
Lint
Lint Skipped
Unit
Unit Tests Skipped

Event Timeline

indygreg created this revision.Sep 26 2018, 9:09 PM
This revision was automatically updated to reflect the committed changes.

Windows doesn't like this test, and gets a connection refused. Under the glob is the machine name instead of $LOCALIP that is used above it. Obviously this isn't the right fix, but this makes the test run on Windows to illustrate it's not something else:

diff --git a/mercurial/wireprotov2peer.py b/mercurial/wireprotov2peer.py
--- a/mercurial/wireprotov2peer.py
+++ b/mercurial/wireprotov2peer.py
@@ -388,6 +388,9 @@ class clienthandler(object):

     def _followredirect(self, requestid, redirect):
         """Called to initiate redirect following for a request."""
+        url = util.url(redirect.url)
+        url.host = '127.0.0.1'
+        redirect.url = str(url)
         self._ui.note(_('(following redirect to %s)\n') % redirect.url)

         # TODO handle framed responses.

This seems like the problem I mentioned in D3433 on May 2 that you thought boiled down to a gethostname(). Not sure what to do about it.