Show More
@@ -153,7 +153,7 b' def ispathsafe(path):' | |||||
153 |
|
153 | |||
154 | return True |
|
154 | return True | |
155 |
|
155 | |||
156 |
def staticfile(directory, fname, re |
|
156 | def staticfile(directory, fname, res): | |
157 | """return a file inside directory with guessed Content-Type header |
|
157 | """return a file inside directory with guessed Content-Type header | |
158 |
|
158 | |||
159 | fname always uses '/' as directory separator and isn't allowed to |
|
159 | fname always uses '/' as directory separator and isn't allowed to | |
@@ -178,7 +178,9 b' def staticfile(directory, fname, req):' | |||||
178 | with open(path, 'rb') as fh: |
|
178 | with open(path, 'rb') as fh: | |
179 | data = fh.read() |
|
179 | data = fh.read() | |
180 |
|
180 | |||
181 | req.respond(HTTP_OK, ct, body=data) |
|
181 | res.headers['Content-Type'] = ct | |
|
182 | res.setbodybytes(data) | |||
|
183 | return res | |||
182 | except TypeError: |
|
184 | except TypeError: | |
183 | raise ErrorResponse(HTTP_SERVER_ERROR, 'illegal filename') |
|
185 | raise ErrorResponse(HTTP_SERVER_ERROR, 'illegal filename') | |
184 | except OSError as err: |
|
186 | except OSError as err: |
@@ -230,12 +230,14 b' class hgwebdir(object):' | |||||
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('/') | |
@@ -243,6 +245,10 b' class hgwebdir(object):' | |||||
243 | ctype = tmpl('mimetype', encoding=encoding.encoding) |
|
245 | ctype = tmpl('mimetype', encoding=encoding.encoding) | |
244 | ctype = templater.stringify(ctype) |
|
246 | ctype = templater.stringify(ctype) | |
245 |
|
247 | |||
|
248 | # Global defaults. These can be overridden by any handler. | |||
|
249 | res.status = '200 Script output follows' | |||
|
250 | res.headers['Content-Type'] = ctype | |||
|
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/'): | |
@@ -256,8 +262,9 b' class hgwebdir(object):' | |||||
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 |
@@ -1232,8 +1232,9 b' def static(web, req, tmpl):' | |||||
1232 | if isinstance(tp, str): |
|
1232 | if isinstance(tp, str): | |
1233 | tp = [tp] |
|
1233 | tp = [tp] | |
1234 | static = [os.path.join(p, 'static') for p in tp] |
|
1234 | static = [os.path.join(p, 'static') for p in tp] | |
1235 | staticfile(static, fname, req) |
|
1235 | ||
1236 | return [] |
|
1236 | staticfile(static, fname, web.res) | |
|
1237 | return web.res | |||
1237 |
|
1238 | |||
1238 | @webcommand('graph') |
|
1239 | @webcommand('graph') | |
1239 | def graph(web, req, tmpl): |
|
1240 | def graph(web, req, tmpl): |
General Comments 0
You need to be logged in to leave comments.
Login now