Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/hgweb/hgweb_mod.py @ 36820:158d4ecc03c8
wireprotoserver: move all wire protocol handling logic out of hgweb
Previous patches from several days ago worked to isolate processing
of HTTP wire protocol requests to wireprotoserver. We still had a
little logic in hgweb. If feels like the right time to finish the
job.
This commit moves WSGI request servicing from hgweb to wireprotoserver.
The ugly dict holding the parsed request is no more. I think the new
code is cleaner.
As part of this, we now process wire protocol requests before the
block to obtain the "query" variable. This makes it clear that this
wonky "query" variable is not used by the wire protocol.
The wonkiest part about this code is the HTTP 404. I'm actually not
sure what all is going on here. It looks like the code is trying to
prevent URL with path components that specify a command from not
working. That part I grok. What I don't grok is why we need to send
a 404. I would think it would be OK to no-op and let another handler
try to service the request. But if we do this, we get some subrepo
test failures. So it looks like something is expecting the HTTP 404
and reacting to it in a specific way. It /might/ be possible to
change the behavior here. But it isn't something I'm comfortable
doing because I don't understand the problem space.
Differential Revision: https://phab.mercurial-scm.org/D2740
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Thu, 08 Mar 2018 15:58:52 -0800 |
parents | cfb9ef24968c |
children | f9078c6caeb6 |
comparison
equal
deleted
inserted
replaced
36819:cfb9ef24968c | 36820:158d4ecc03c8 |
---|---|
316 # replace it. | 316 # replace it. |
317 wsgireq.headers = [h for h in wsgireq.headers | 317 wsgireq.headers = [h for h in wsgireq.headers |
318 if h[0] != 'Content-Security-Policy'] | 318 if h[0] != 'Content-Security-Policy'] |
319 wsgireq.headers.append(('Content-Security-Policy', rctx.csp)) | 319 wsgireq.headers.append(('Content-Security-Policy', rctx.csp)) |
320 | 320 |
321 handled, res = wireprotoserver.handlewsgirequest( | |
322 rctx, wsgireq, req, self.check_perm) | |
323 if handled: | |
324 return res | |
325 | |
321 if req.havepathinfo: | 326 if req.havepathinfo: |
322 query = req.dispatchpath | 327 query = req.dispatchpath |
323 else: | 328 else: |
324 query = req.querystring.partition('&')[0].partition(';')[0] | 329 query = req.querystring.partition('&')[0].partition(';')[0] |
325 | |
326 # Route it to a wire protocol handler if it looks like a wire protocol | |
327 # request. | |
328 protohandler = wireprotoserver.parsehttprequest(rctx, wsgireq, req, | |
329 self.check_perm) | |
330 | |
331 if protohandler: | |
332 try: | |
333 if query: | |
334 raise ErrorResponse(HTTP_NOT_FOUND) | |
335 | |
336 return protohandler['dispatch']() | |
337 except ErrorResponse as inst: | |
338 return protohandler['handleerror'](inst) | |
339 | 330 |
340 # translate user-visible url structure to internal structure | 331 # translate user-visible url structure to internal structure |
341 | 332 |
342 args = query.split('/', 2) | 333 args = query.split('/', 2) |
343 if 'cmd' not in wsgireq.form and args and args[0]: | 334 if 'cmd' not in wsgireq.form and args and args[0]: |