Show More
@@ -153,7 +153,7 def ispathsafe(path): | |||
|
153 | 153 | |
|
154 | 154 | return True |
|
155 | 155 | |
|
156 |
def staticfile(directory, fname, re |
|
|
156 | def staticfile(directory, fname, res): | |
|
157 | 157 | """return a file inside directory with guessed Content-Type header |
|
158 | 158 | |
|
159 | 159 | fname always uses '/' as directory separator and isn't allowed to |
@@ -178,7 +178,9 def staticfile(directory, fname, req): | |||
|
178 | 178 | with open(path, 'rb') as fh: |
|
179 | 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 | 184 | except TypeError: |
|
183 | 185 | raise ErrorResponse(HTTP_SERVER_ERROR, 'illegal filename') |
|
184 | 186 | except OSError as err: |
@@ -230,12 +230,14 class hgwebdir(object): | |||
|
230 | 230 | |
|
231 | 231 | def _runwsgi(self, wsgireq): |
|
232 | 232 | req = wsgireq.req |
|
233 | res = wsgireq.res | |
|
233 | 234 | |
|
234 | 235 | try: |
|
235 | 236 | self.refresh() |
|
236 | 237 | |
|
237 | 238 | csp, nonce = cspvalues(self.ui) |
|
238 | 239 | if csp: |
|
240 | res.headers['Content-Security-Policy'] = csp | |
|
239 | 241 | wsgireq.headers.append(('Content-Security-Policy', csp)) |
|
240 | 242 | |
|
241 | 243 | virtual = wsgireq.env.get("PATH_INFO", "").strip('/') |
@@ -243,6 +245,10 class hgwebdir(object): | |||
|
243 | 245 | ctype = tmpl('mimetype', encoding=encoding.encoding) |
|
244 | 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 | 252 | # a static file |
|
247 | 253 | if virtual.startswith('static/') or 'static' in req.qsparams: |
|
248 | 254 | if virtual.startswith('static/'): |
@@ -256,8 +262,9 class hgwebdir(object): | |||
|
256 | 262 | if isinstance(tp, str): |
|
257 | 263 | tp = [tp] |
|
258 | 264 | static = [os.path.join(p, 'static') for p in tp] |
|
259 | staticfile(static, fname, wsgireq) | |
|
260 | return [] | |
|
265 | ||
|
266 | staticfile(static, fname, res) | |
|
267 | return res.sendresponse() | |
|
261 | 268 | |
|
262 | 269 | # top-level index |
|
263 | 270 |
@@ -1232,8 +1232,9 def static(web, req, tmpl): | |||
|
1232 | 1232 | if isinstance(tp, str): |
|
1233 | 1233 | tp = [tp] |
|
1234 | 1234 | static = [os.path.join(p, 'static') for p in tp] |
|
1235 | staticfile(static, fname, req) | |
|
1236 | return [] | |
|
1235 | ||
|
1236 | staticfile(static, fname, web.res) | |
|
1237 | return web.res | |
|
1237 | 1238 | |
|
1238 | 1239 | @webcommand('graph') |
|
1239 | 1240 | def graph(web, req, tmpl): |
General Comments 0
You need to be logged in to leave comments.
Login now