366 cmd = req.qsparams.get('cmd', '') |
370 cmd = req.qsparams.get('cmd', '') |
367 |
371 |
368 # process the web interface request |
372 # process the web interface request |
369 |
373 |
370 try: |
374 try: |
371 tmpl = rctx.templater(req) |
375 rctx.tmpl = rctx.templater(req) |
372 ctype = tmpl('mimetype', encoding=encoding.encoding) |
376 ctype = rctx.tmpl('mimetype', encoding=encoding.encoding) |
373 ctype = templater.stringify(ctype) |
377 ctype = templater.stringify(ctype) |
374 |
378 |
375 # check read permissions non-static content |
379 # check read permissions non-static content |
376 if cmd != 'static': |
380 if cmd != 'static': |
377 self.check_perm(rctx, req, None) |
381 self.check_perm(rctx, req, None) |
378 |
382 |
379 if cmd == '': |
383 if cmd == '': |
380 req.qsparams['cmd'] = tmpl.cache['default'] |
384 req.qsparams['cmd'] = rctx.tmpl.cache['default'] |
381 cmd = req.qsparams['cmd'] |
385 cmd = req.qsparams['cmd'] |
382 |
386 |
383 # Don't enable caching if using a CSP nonce because then it wouldn't |
387 # Don't enable caching if using a CSP nonce because then it wouldn't |
384 # be a nonce. |
388 # be a nonce. |
385 if rctx.configbool('web', 'cache') and not rctx.nonce: |
389 if rctx.configbool('web', 'cache') and not rctx.nonce: |
398 else: |
402 else: |
399 # Set some globals appropriate for web handlers. Commands can |
403 # Set some globals appropriate for web handlers. Commands can |
400 # override easily enough. |
404 # override easily enough. |
401 res.status = '200 Script output follows' |
405 res.status = '200 Script output follows' |
402 res.headers['Content-Type'] = ctype |
406 res.headers['Content-Type'] = ctype |
403 return getattr(webcommands, cmd)(rctx, wsgireq, tmpl) |
407 return getattr(webcommands, cmd)(rctx, wsgireq, rctx.tmpl) |
404 |
408 |
405 except (error.LookupError, error.RepoLookupError) as err: |
409 except (error.LookupError, error.RepoLookupError) as err: |
406 msg = pycompat.bytestr(err) |
410 msg = pycompat.bytestr(err) |
407 if (util.safehasattr(err, 'name') and |
411 if (util.safehasattr(err, 'name') and |
408 not isinstance(err, error.ManifestLookupError)): |
412 not isinstance(err, error.ManifestLookupError)): |
409 msg = 'revision not found: %s' % err.name |
413 msg = 'revision not found: %s' % err.name |
410 |
414 |
411 res.status = '404 Not Found' |
415 res.status = '404 Not Found' |
412 res.headers['Content-Type'] = ctype |
416 res.headers['Content-Type'] = ctype |
413 res.setbodygen(tmpl('error', error=msg)) |
417 return rctx.sendtemplate('error', error=msg) |
414 return res.sendresponse() |
|
415 except (error.RepoError, error.RevlogError) as e: |
418 except (error.RepoError, error.RevlogError) as e: |
416 res.status = '500 Internal Server Error' |
419 res.status = '500 Internal Server Error' |
417 res.headers['Content-Type'] = ctype |
420 res.headers['Content-Type'] = ctype |
418 res.setbodygen(tmpl('error', error=pycompat.bytestr(e))) |
421 return rctx.sendtemplate('error', error=pycompat.bytestr(e)) |
419 return res.sendresponse() |
|
420 except ErrorResponse as e: |
422 except ErrorResponse as e: |
421 res.status = statusmessage(e.code, pycompat.bytestr(e)) |
423 res.status = statusmessage(e.code, pycompat.bytestr(e)) |
422 res.headers['Content-Type'] = ctype |
424 res.headers['Content-Type'] = ctype |
423 res.setbodygen(tmpl('error', error=pycompat.bytestr(e))) |
425 return rctx.sendtemplate('error', error=pycompat.bytestr(e)) |
424 return res.sendresponse() |
|
425 |
426 |
426 def check_perm(self, rctx, req, op): |
427 def check_perm(self, rctx, req, op): |
427 for permhook in permhooks: |
428 for permhook in permhooks: |
428 permhook(rctx, req, op) |
429 permhook(rctx, req, op) |
429 |
430 |