comparison mercurial/hgweb/hgweb_mod.py @ 36819:cfb9ef24968c

hgweb: use parsed request to construct query parameters The way hgweb routes requests is kind of bonkers. If PATH_INFO is set, we take the URL path after the repository. Otherwise, we take the first part of the query string before "&" and the part before ";" in that. We then kinda/sorta treat this as a path and route based on that. This commit ports that code to use the parsed request object. This required a new attribute on the parsed request to indicate whether there is any PATH_INFO. The new code still feels a bit convoluted for my liking. But we'll need to rewrite more of the code before a better solution becomes apparant. This code feels strictly better since we're no longer doing low-level WSGI manipulation during routing. Differential Revision: https://phab.mercurial-scm.org/D2739
author Gregory Szorc <gregory.szorc@gmail.com>
date Thu, 08 Mar 2018 15:37:05 -0800
parents 886fba199022
children 158d4ecc03c8
comparison
equal deleted inserted replaced
36818:886fba199022 36819:cfb9ef24968c
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 if r'PATH_INFO' in wsgireq.env: 321 if req.havepathinfo:
322 parts = wsgireq.env[r'PATH_INFO'].strip(r'/').split(r'/') 322 query = req.dispatchpath
323 repo_parts = wsgireq.env.get(r'REPO_NAME', r'').split(r'/')
324 if parts[:len(repo_parts)] == repo_parts:
325 parts = parts[len(repo_parts):]
326 query = r'/'.join(parts)
327 else: 323 else:
328 query = wsgireq.env[r'QUERY_STRING'].partition(r'&')[0] 324 query = req.querystring.partition('&')[0].partition(';')[0]
329 query = query.partition(r';')[0]
330 325
331 # Route it to a wire protocol handler if it looks like a wire protocol 326 # Route it to a wire protocol handler if it looks like a wire protocol
332 # request. 327 # request.
333 protohandler = wireprotoserver.parsehttprequest(rctx, wsgireq, req, 328 protohandler = wireprotoserver.parsehttprequest(rctx, wsgireq, req,
334 self.check_perm) 329 self.check_perm)
342 except ErrorResponse as inst: 337 except ErrorResponse as inst:
343 return protohandler['handleerror'](inst) 338 return protohandler['handleerror'](inst)
344 339
345 # translate user-visible url structure to internal structure 340 # translate user-visible url structure to internal structure
346 341
347 args = query.split(r'/', 2) 342 args = query.split('/', 2)
348 if 'cmd' not in wsgireq.form and args and args[0]: 343 if 'cmd' not in wsgireq.form and args and args[0]:
349 cmd = args.pop(0) 344 cmd = args.pop(0)
350 style = cmd.rfind('-') 345 style = cmd.rfind('-')
351 if style != -1: 346 if style != -1:
352 wsgireq.form['style'] = [cmd[:style]] 347 wsgireq.form['style'] = [cmd[:style]]