comparison mercurial/hgweb/hgweb_mod.py @ 36865:3d60a22e27f5

hgweb: perform all parameter lookup via qsparams I think I managed to update all call sites using wsgirequest.form to use parsedrequest.qsparams. Since behavior of qsparams is to retrieve last value, behavior will change if a parameter was specified multiple times. But I think this is acceptable. I'm not a fan of the `req.req.qsparams` pattern. And some of the modified code could be written better. But I was aiming for a straight port with this change. Cleanup can come later. Differential Revision: https://phab.mercurial-scm.org/D2781
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 10 Mar 2018 12:36:36 -0800
parents 4e06e8336634
children cf69df7ea385
comparison
equal deleted inserted replaced
36864:4e06e8336634 36865:3d60a22e27f5
330 query = req.querystring.partition('&')[0].partition(';')[0] 330 query = req.querystring.partition('&')[0].partition(';')[0]
331 331
332 # translate user-visible url structure to internal structure 332 # translate user-visible url structure to internal structure
333 333
334 args = query.split('/', 2) 334 args = query.split('/', 2)
335 if 'cmd' not in wsgireq.form and args and args[0]: 335 if 'cmd' not in req.qsparams and args and args[0]:
336 cmd = args.pop(0) 336 cmd = args.pop(0)
337 style = cmd.rfind('-') 337 style = cmd.rfind('-')
338 if style != -1: 338 if style != -1:
339 req.qsparams['style'] = cmd[:style] 339 req.qsparams['style'] = cmd[:style]
340 cmd = cmd[style + 1:] 340 cmd = cmd[style + 1:]
362 ua = req.headers.get('User-Agent', '') 362 ua = req.headers.get('User-Agent', '')
363 if cmd == 'rev' and 'mercurial' in ua: 363 if cmd == 'rev' and 'mercurial' in ua:
364 req.qsparams['style'] = 'raw' 364 req.qsparams['style'] = 'raw'
365 365
366 if cmd == 'archive': 366 if cmd == 'archive':
367 fn = wsgireq.form['node'][0] 367 fn = req.qsparams['node']
368 for type_, spec in rctx.archivespecs.iteritems(): 368 for type_, spec in rctx.archivespecs.iteritems():
369 ext = spec[2] 369 ext = spec[2]
370 if fn.endswith(ext): 370 if fn.endswith(ext):
371 wsgireq.form['node'] = [fn[:-len(ext)]] 371 wsgireq.form['node'] = [fn[:-len(ext)]]
372 req.qsparams['node'] = fn[:-len(next)] 372 req.qsparams['node'] = fn[:-len(ext)]
373 wsgireq.form['type'] = [type_] 373 wsgireq.form['type'] = [type_]
374 req.qsparams['type'] = type_ 374 req.qsparams['type'] = type_
375 else: 375 else:
376 cmd = wsgireq.form.get('cmd', [''])[0] 376 cmd = req.qsparams.get('cmd', '')
377 377
378 # process the web interface request 378 # process the web interface request
379 379
380 try: 380 try:
381 tmpl = rctx.templater(wsgireq, req) 381 tmpl = rctx.templater(wsgireq, req)
387 self.check_perm(rctx, wsgireq, None) 387 self.check_perm(rctx, wsgireq, None)
388 388
389 if cmd == '': 389 if cmd == '':
390 wsgireq.form['cmd'] = [tmpl.cache['default']] 390 wsgireq.form['cmd'] = [tmpl.cache['default']]
391 req.qsparams['cmd'] = tmpl.cache['default'] 391 req.qsparams['cmd'] = tmpl.cache['default']
392 cmd = wsgireq.form['cmd'][0] 392 cmd = req.qsparams['cmd']
393 393
394 # Don't enable caching if using a CSP nonce because then it wouldn't 394 # Don't enable caching if using a CSP nonce because then it wouldn't
395 # be a nonce. 395 # be a nonce.
396 if rctx.configbool('web', 'cache') and not rctx.nonce: 396 if rctx.configbool('web', 'cache') and not rctx.nonce:
397 caching(self, wsgireq) # sets ETag header or raises NOT_MODIFIED 397 caching(self, wsgireq) # sets ETag header or raises NOT_MODIFIED