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