Mercurial > hg
comparison mercurial/hgweb/hgwebdir_mod.py @ 36873:98baf8dea553
hgweb: port static file handling to new response API
hgwebdir_mod hasn't received as much porting effort. So we had to
do some minor plumbing to get it to match hgweb_mod and to support
the new response object.
Differential Revision: https://phab.mercurial-scm.org/D2789
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sat, 10 Mar 2018 15:46:29 -0800 |
parents | 3d60a22e27f5 |
children | 97e1dda94af8 |
comparison
equal
deleted
inserted
replaced
36872:89002d07a114 | 36873:98baf8dea553 |
---|---|
228 for r in self._runwsgi(wsgireq): | 228 for r in self._runwsgi(wsgireq): |
229 yield r | 229 yield r |
230 | 230 |
231 def _runwsgi(self, wsgireq): | 231 def _runwsgi(self, wsgireq): |
232 req = wsgireq.req | 232 req = wsgireq.req |
233 res = wsgireq.res | |
233 | 234 |
234 try: | 235 try: |
235 self.refresh() | 236 self.refresh() |
236 | 237 |
237 csp, nonce = cspvalues(self.ui) | 238 csp, nonce = cspvalues(self.ui) |
238 if csp: | 239 if csp: |
240 res.headers['Content-Security-Policy'] = csp | |
239 wsgireq.headers.append(('Content-Security-Policy', csp)) | 241 wsgireq.headers.append(('Content-Security-Policy', csp)) |
240 | 242 |
241 virtual = wsgireq.env.get("PATH_INFO", "").strip('/') | 243 virtual = wsgireq.env.get("PATH_INFO", "").strip('/') |
242 tmpl = self.templater(wsgireq, nonce) | 244 tmpl = self.templater(wsgireq, nonce) |
243 ctype = tmpl('mimetype', encoding=encoding.encoding) | 245 ctype = tmpl('mimetype', encoding=encoding.encoding) |
244 ctype = templater.stringify(ctype) | 246 ctype = templater.stringify(ctype) |
247 | |
248 # Global defaults. These can be overridden by any handler. | |
249 res.status = '200 Script output follows' | |
250 res.headers['Content-Type'] = ctype | |
245 | 251 |
246 # a static file | 252 # a static file |
247 if virtual.startswith('static/') or 'static' in req.qsparams: | 253 if virtual.startswith('static/') or 'static' in req.qsparams: |
248 if virtual.startswith('static/'): | 254 if virtual.startswith('static/'): |
249 fname = virtual[7:] | 255 fname = virtual[7:] |
254 if not static: | 260 if not static: |
255 tp = self.templatepath or templater.templatepaths() | 261 tp = self.templatepath or templater.templatepaths() |
256 if isinstance(tp, str): | 262 if isinstance(tp, str): |
257 tp = [tp] | 263 tp = [tp] |
258 static = [os.path.join(p, 'static') for p in tp] | 264 static = [os.path.join(p, 'static') for p in tp] |
259 staticfile(static, fname, wsgireq) | 265 |
260 return [] | 266 staticfile(static, fname, res) |
267 return res.sendresponse() | |
261 | 268 |
262 # top-level index | 269 # top-level index |
263 | 270 |
264 repos = dict(self.repos) | 271 repos = dict(self.repos) |
265 | 272 |