equal
deleted
inserted
replaced
17 from .common import ( |
17 from .common import ( |
18 ErrorResponse, |
18 ErrorResponse, |
19 HTTP_NOT_FOUND, |
19 HTTP_NOT_FOUND, |
20 HTTP_OK, |
20 HTTP_OK, |
21 HTTP_SERVER_ERROR, |
21 HTTP_SERVER_ERROR, |
|
22 cspvalues, |
22 get_contact, |
23 get_contact, |
23 get_mtime, |
24 get_mtime, |
24 ismember, |
25 ismember, |
25 paritygen, |
26 paritygen, |
26 staticfile, |
27 staticfile, |
225 |
226 |
226 def _runwsgi(self, req): |
227 def _runwsgi(self, req): |
227 try: |
228 try: |
228 self.refresh() |
229 self.refresh() |
229 |
230 |
|
231 csp, nonce = cspvalues(self.ui) |
|
232 if csp: |
|
233 req.headers.append(('Content-Security-Policy', csp)) |
|
234 |
230 virtual = req.env.get("PATH_INFO", "").strip('/') |
235 virtual = req.env.get("PATH_INFO", "").strip('/') |
231 tmpl = self.templater(req) |
236 tmpl = self.templater(req, nonce) |
232 ctype = tmpl('mimetype', encoding=encoding.encoding) |
237 ctype = tmpl('mimetype', encoding=encoding.encoding) |
233 ctype = templater.stringify(ctype) |
238 ctype = templater.stringify(ctype) |
234 |
239 |
235 # a static file |
240 # a static file |
236 if virtual.startswith('static/') or 'static' in req.form: |
241 if virtual.startswith('static/') or 'static' in req.form: |
464 return tmpl("index", entries=entries, subdir=subdir, |
469 return tmpl("index", entries=entries, subdir=subdir, |
465 pathdef=hgweb_mod.makebreadcrumb('/' + subdir, self.prefix), |
470 pathdef=hgweb_mod.makebreadcrumb('/' + subdir, self.prefix), |
466 sortcolumn=sortcolumn, descending=descending, |
471 sortcolumn=sortcolumn, descending=descending, |
467 **dict(sort)) |
472 **dict(sort)) |
468 |
473 |
469 def templater(self, req): |
474 def templater(self, req, nonce): |
470 |
475 |
471 def motd(**map): |
476 def motd(**map): |
472 if self.motd is not None: |
477 if self.motd is not None: |
473 yield self.motd |
478 yield self.motd |
474 else: |
479 else: |
508 "logourl": logourl, |
513 "logourl": logourl, |
509 "logoimg": logoimg, |
514 "logoimg": logoimg, |
510 "staticurl": staticurl, |
515 "staticurl": staticurl, |
511 "sessionvars": sessionvars, |
516 "sessionvars": sessionvars, |
512 "style": style, |
517 "style": style, |
|
518 "nonce": nonce, |
513 } |
519 } |
514 tmpl = templater.templater.frommapfile(mapfile, defaults=defaults) |
520 tmpl = templater.templater.frommapfile(mapfile, defaults=defaults) |
515 return tmpl |
521 return tmpl |
516 |
522 |
517 def updatereqenv(self, env): |
523 def updatereqenv(self, env): |