Patchwork D2783: hgweb: expose URL scheme and REMOTE_* attributes

login
register
mail settings
Submitter phabricator
Date March 12, 2018, 9:33 p.m.
Message ID <6d1c1a53e82a9503d057d9b9c462f3dd@localhost.localdomain>
Download mbox | patch
Permalink /patch/29361/
State Not Applicable
Headers show

Comments

phabricator - March 12, 2018, 9:33 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHGa755fd3b7146: hgweb: expose URL scheme and REMOTE_* attributes (authored by indygreg, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D2783?vs=6844&id=6919

REVISION DETAIL
  https://phab.mercurial-scm.org/D2783

AFFECTED FILES
  mercurial/hgweb/request.py
  mercurial/wireprotoserver.py

CHANGE DETAILS




To: indygreg, #hg-reviewers, durin42
Cc: mercurial-devel

Patch

diff --git a/mercurial/wireprotoserver.py b/mercurial/wireprotoserver.py
--- a/mercurial/wireprotoserver.py
+++ b/mercurial/wireprotoserver.py
@@ -53,8 +53,7 @@ 
     return ''.join(chunks)
 
 class httpv1protocolhandler(wireprototypes.baseprotocolhandler):
-    def __init__(self, wsgireq, req, ui, checkperm):
-        self._wsgireq = wsgireq
+    def __init__(self, req, ui, checkperm):
         self._req = req
         self._ui = ui
         self._checkperm = checkperm
@@ -117,9 +116,9 @@ 
 
     def client(self):
         return 'remote:%s:%s:%s' % (
-            self._wsgireq.env.get('wsgi.url_scheme') or 'http',
-            urlreq.quote(self._wsgireq.env.get('REMOTE_HOST', '')),
-            urlreq.quote(self._wsgireq.env.get('REMOTE_USER', '')))
+            self._req.urlscheme,
+            urlreq.quote(self._req.remotehost or ''),
+            urlreq.quote(self._req.remoteuser or ''))
 
     def addcapabilities(self, repo, caps):
         caps.append('httpheader=%d' %
@@ -197,15 +196,15 @@ 
         res.setbodybytes('0\n%s\n' % b'Not Found')
         return True
 
-    proto = httpv1protocolhandler(wsgireq, req, repo.ui,
+    proto = httpv1protocolhandler(req, repo.ui,
                                   lambda perm: checkperm(rctx, wsgireq, perm))
 
     # The permissions checker should be the only thing that can raise an
     # ErrorResponse. It is kind of a layer violation to catch an hgweb
     # exception here. So consider refactoring into a exception type that
     # is associated with the wire protocol.
     try:
-        _callhttp(repo, wsgireq, req, res, proto, cmd)
+        _callhttp(repo, req, res, proto, cmd)
     except hgwebcommon.ErrorResponse as e:
         for k, v in e.headers:
             res.headers[k] = v
@@ -256,7 +255,7 @@ 
     opts = {'level': ui.configint('server', 'zliblevel')}
     return HGTYPE, util.compengines['zlib'], opts
 
-def _callhttp(repo, wsgireq, req, res, proto, cmd):
+def _callhttp(repo, req, res, proto, cmd):
     # Avoid cycle involving hg module.
     from .hgweb import common as hgwebcommon
 
diff --git a/mercurial/hgweb/request.py b/mercurial/hgweb/request.py
--- a/mercurial/hgweb/request.py
+++ b/mercurial/hgweb/request.py
@@ -129,6 +129,12 @@ 
     # of HTTP: Host header for hostname. This is likely what clients used.
     advertisedurl = attr.ib()
     advertisedbaseurl = attr.ib()
+    # URL scheme (part before ``://``). e.g. ``http`` or ``https``.
+    urlscheme = attr.ib()
+    # Value of REMOTE_USER, if set, or None.
+    remoteuser = attr.ib()
+    # Value of REMOTE_HOST, if set, or None.
+    remotehost = attr.ib()
     # WSGI application path.
     apppath = attr.ib()
     # List of path parts to be used for dispatch.
@@ -270,6 +276,9 @@ 
                          url=fullurl, baseurl=baseurl,
                          advertisedurl=advertisedfullurl,
                          advertisedbaseurl=advertisedbaseurl,
+                         urlscheme=env['wsgi.url_scheme'],
+                         remoteuser=env.get('REMOTE_USER'),
+                         remotehost=env.get('REMOTE_HOST'),
                          apppath=apppath,
                          dispatchparts=dispatchparts, dispatchpath=dispatchpath,
                          havepathinfo='PATH_INFO' in env,