diff mercurial/wireprotoserver.py @ 36873:a755fd3b7146

hgweb: expose URL scheme and REMOTE_* attributes These are consulted by the HTTP wire protocol handler by reading from the env dict. Let's expose them as attributes instead. With the wire protocol handler updates to use the new attributes, we no longer have any consumers of the legacy wsgirequest type in the wire protocol code (outside of a proxied call to the permissions checker). So, we remove most references to it. Differential Revision: https://phab.mercurial-scm.org/D2783
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 10 Mar 2018 14:00:40 -0800
parents ec0af9c59270
children 02bea04b4c54
line wrap: on
line diff
--- a/mercurial/wireprotoserver.py	Sat Mar 10 12:31:11 2018 -0800
+++ b/mercurial/wireprotoserver.py	Sat Mar 10 14:00:40 2018 -0800
@@ -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,7 +196,7 @@
         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
@@ -205,7 +204,7 @@
     # 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