comparison mercurial/hgweb/hgweb_mod.py @ 36713:2442927cdd96

hgweb: convert req.form to bytes for all keys and values This is just going to be a lot cleaner for our internals. Differential Revision: https://phab.mercurial-scm.org/D2660
author Augie Fackler <augie@google.com>
date Sun, 04 Mar 2018 13:03:22 -0500
parents 7937850a523d
children 7bf80d9d9543
comparison
equal deleted inserted replaced
36712:e79adc12cde3 36713:2442927cdd96
375 return protohandler['dispatch']() 375 return protohandler['dispatch']()
376 376
377 # translate user-visible url structure to internal structure 377 # translate user-visible url structure to internal structure
378 378
379 args = query.split('/', 2) 379 args = query.split('/', 2)
380 if r'cmd' not in req.form and args and args[0]: 380 if 'cmd' not in req.form and args and args[0]:
381 cmd = args.pop(0) 381 cmd = args.pop(0)
382 style = cmd.rfind('-') 382 style = cmd.rfind('-')
383 if style != -1: 383 if style != -1:
384 req.form['style'] = [cmd[:style]] 384 req.form['style'] = [cmd[:style]]
385 cmd = cmd[style + 1:] 385 cmd = cmd[style + 1:]
386 386
387 # avoid accepting e.g. style parameter as command 387 # avoid accepting e.g. style parameter as command
388 if util.safehasattr(webcommands, cmd): 388 if util.safehasattr(webcommands, cmd):
389 req.form[r'cmd'] = [cmd] 389 req.form['cmd'] = [cmd]
390 390
391 if cmd == 'static': 391 if cmd == 'static':
392 req.form['file'] = ['/'.join(args)] 392 req.form['file'] = ['/'.join(args)]
393 else: 393 else:
394 if args and args[0]: 394 if args and args[0]:
407 ext = spec[2] 407 ext = spec[2]
408 if fn.endswith(ext): 408 if fn.endswith(ext):
409 req.form['node'] = [fn[:-len(ext)]] 409 req.form['node'] = [fn[:-len(ext)]]
410 req.form['type'] = [type_] 410 req.form['type'] = [type_]
411 else: 411 else:
412 cmd = pycompat.sysbytes(req.form.get(r'cmd', [r''])[0]) 412 cmd = req.form.get('cmd', [''])[0]
413 413
414 # process the web interface request 414 # process the web interface request
415 415
416 try: 416 try:
417 tmpl = rctx.templater(req) 417 tmpl = rctx.templater(req)
421 # check read permissions non-static content 421 # check read permissions non-static content
422 if cmd != 'static': 422 if cmd != 'static':
423 self.check_perm(rctx, req, None) 423 self.check_perm(rctx, req, None)
424 424
425 if cmd == '': 425 if cmd == '':
426 req.form[r'cmd'] = [tmpl.cache['default']] 426 req.form['cmd'] = [tmpl.cache['default']]
427 cmd = req.form[r'cmd'][0] 427 cmd = req.form['cmd'][0]
428 428
429 # Don't enable caching if using a CSP nonce because then it wouldn't 429 # Don't enable caching if using a CSP nonce because then it wouldn't
430 # be a nonce. 430 # be a nonce.
431 if rctx.configbool('web', 'cache') and not rctx.nonce: 431 if rctx.configbool('web', 'cache') and not rctx.nonce:
432 caching(self, req) # sets ETag header or raises NOT_MODIFIED 432 caching(self, req) # sets ETag header or raises NOT_MODIFIED
433 if cmd not in webcommands.__all__: 433 if cmd not in webcommands.__all__:
434 msg = 'no such method: %s' % cmd 434 msg = 'no such method: %s' % cmd
435 raise ErrorResponse(HTTP_BAD_REQUEST, msg) 435 raise ErrorResponse(HTTP_BAD_REQUEST, msg)
436 elif cmd == 'file' and r'raw' in req.form.get(r'style', []): 436 elif cmd == 'file' and 'raw' in req.form.get('style', []):
437 rctx.ctype = ctype 437 rctx.ctype = ctype
438 content = webcommands.rawfile(rctx, req, tmpl) 438 content = webcommands.rawfile(rctx, req, tmpl)
439 else: 439 else:
440 content = getattr(webcommands, cmd)(rctx, req, tmpl) 440 content = getattr(webcommands, cmd)(rctx, req, tmpl)
441 req.respond(HTTP_OK, ctype) 441 req.respond(HTTP_OK, ctype)