##// END OF EJS Templates
hgweb: expose URL scheme and REMOTE_* attributes...
Gregory Szorc -
r36883:a755fd3b default
parent child Browse files
Show More
@@ -129,6 +129,12 b' class parsedrequest(object):'
129 129 # of HTTP: Host header for hostname. This is likely what clients used.
130 130 advertisedurl = attr.ib()
131 131 advertisedbaseurl = attr.ib()
132 # URL scheme (part before ``://``). e.g. ``http`` or ``https``.
133 urlscheme = attr.ib()
134 # Value of REMOTE_USER, if set, or None.
135 remoteuser = attr.ib()
136 # Value of REMOTE_HOST, if set, or None.
137 remotehost = attr.ib()
132 138 # WSGI application path.
133 139 apppath = attr.ib()
134 140 # List of path parts to be used for dispatch.
@@ -270,6 +276,9 b' def parserequestfromenv(env, bodyfh):'
270 276 url=fullurl, baseurl=baseurl,
271 277 advertisedurl=advertisedfullurl,
272 278 advertisedbaseurl=advertisedbaseurl,
279 urlscheme=env['wsgi.url_scheme'],
280 remoteuser=env.get('REMOTE_USER'),
281 remotehost=env.get('REMOTE_HOST'),
273 282 apppath=apppath,
274 283 dispatchparts=dispatchparts, dispatchpath=dispatchpath,
275 284 havepathinfo='PATH_INFO' in env,
@@ -53,8 +53,7 b' def decodevaluefromheaders(req, headerpr'
53 53 return ''.join(chunks)
54 54
55 55 class httpv1protocolhandler(wireprototypes.baseprotocolhandler):
56 def __init__(self, wsgireq, req, ui, checkperm):
57 self._wsgireq = wsgireq
56 def __init__(self, req, ui, checkperm):
58 57 self._req = req
59 58 self._ui = ui
60 59 self._checkperm = checkperm
@@ -117,9 +116,9 b' class httpv1protocolhandler(wireprototyp'
117 116
118 117 def client(self):
119 118 return 'remote:%s:%s:%s' % (
120 self._wsgireq.env.get('wsgi.url_scheme') or 'http',
121 urlreq.quote(self._wsgireq.env.get('REMOTE_HOST', '')),
122 urlreq.quote(self._wsgireq.env.get('REMOTE_USER', '')))
119 self._req.urlscheme,
120 urlreq.quote(self._req.remotehost or ''),
121 urlreq.quote(self._req.remoteuser or ''))
123 122
124 123 def addcapabilities(self, repo, caps):
125 124 caps.append('httpheader=%d' %
@@ -197,7 +196,7 b' def handlewsgirequest(rctx, wsgireq, req'
197 196 res.setbodybytes('0\n%s\n' % b'Not Found')
198 197 return True
199 198
200 proto = httpv1protocolhandler(wsgireq, req, repo.ui,
199 proto = httpv1protocolhandler(req, repo.ui,
201 200 lambda perm: checkperm(rctx, wsgireq, perm))
202 201
203 202 # The permissions checker should be the only thing that can raise an
@@ -205,7 +204,7 b' def handlewsgirequest(rctx, wsgireq, req'
205 204 # exception here. So consider refactoring into a exception type that
206 205 # is associated with the wire protocol.
207 206 try:
208 _callhttp(repo, wsgireq, req, res, proto, cmd)
207 _callhttp(repo, req, res, proto, cmd)
209 208 except hgwebcommon.ErrorResponse as e:
210 209 for k, v in e.headers:
211 210 res.headers[k] = v
@@ -256,7 +255,7 b' def _httpresponsetype(ui, req, prefer_un'
256 255 opts = {'level': ui.configint('server', 'zliblevel')}
257 256 return HGTYPE, util.compengines['zlib'], opts
258 257
259 def _callhttp(repo, wsgireq, req, res, proto, cmd):
258 def _callhttp(repo, req, res, proto, cmd):
260 259 # Avoid cycle involving hg module.
261 260 from .hgweb import common as hgwebcommon
262 261
General Comments 0
You need to be logged in to leave comments. Login now