##// END OF EJS Templates
hgweb: fast path for sending raw files
Dirkjan Ochtman -
r5890:a0e20a5e default
parent child Browse files
Show More
@@ -206,12 +206,17 b' class hgweb(object):'
206 206 method = getattr(protocol, cmd)
207 207 method(self, req)
208 208 else:
209
209 210 tmpl = self.templater(req)
210 211 if cmd == '':
211 212 req.form['cmd'] = [tmpl.cache['default']]
212 213 cmd = req.form['cmd'][0]
213 method = getattr(webcommands, cmd)
214 method(self, req, tmpl)
214
215 if cmd == 'file' and 'raw' in req.form['style']:
216 webcommands.rawfile(self, req, tmpl)
217 else:
218 getattr(webcommands, cmd)(self, req, tmpl)
219
215 220 del tmpl
216 221
217 222 except revlog.LookupError, err:
@@ -254,12 +259,6 b' class hgweb(object):'
254 259 req.header(msg.items())
255 260 yield header_file.read()
256 261
257 def rawfileheader(**map):
258 req.header([('Content-type', map['mimetype']),
259 ('Content-disposition', 'filename=%s' % map['file']),
260 ('Content-length', str(len(map['raw'])))])
261 yield ''
262
263 262 def footer(**map):
264 263 yield tmpl("footer", **map)
265 264
@@ -300,7 +299,6 b' class hgweb(object):'
300 299 "header": header,
301 300 "footer": footer,
302 301 "motd": motd,
303 "rawfileheader": rawfileheader,
304 302 "sessionvars": sessionvars
305 303 })
306 304 return tmpl
@@ -5,8 +5,8 b''
5 5 # This software may be used and distributed according to the terms
6 6 # of the GNU General Public License, incorporated herein by reference.
7 7
8 import os
9 from mercurial import revlog
8 import os, mimetypes
9 from mercurial import revlog, util
10 10 from common import staticfile
11 11
12 12 def log(web, req, tmpl):
@@ -15,6 +15,27 b' def log(web, req, tmpl):'
15 15 else:
16 16 changelog(web, req, tmpl)
17 17
18 def rawfile(web, req, tmpl):
19 path = web.cleanpath(req.form.get('file', [''])[0])
20 if not path:
21 req.write(web.manifest(tmpl, web.changectx(req), path))
22 return
23
24 try:
25 fctx = web.filectx(req)
26 except revlog.LookupError:
27 req.write(web.manifest(tmpl, web.changectx(req), path))
28 return
29
30 path = fctx.path()
31 text = fctx.data()
32 mt = mimetypes.guess_type(path)[0]
33 if util.binary(text):
34 mt = mt or 'application/octet-stream'
35
36 req.httphdr(mt, path, len(text))
37 req.write(text)
38
18 39 def file(web, req, tmpl):
19 40 path = web.cleanpath(req.form.get('file', [''])[0])
20 41 if path:
@@ -8,7 +8,6 b" diffline = '#line#'"
8 8 changesetparent = '# Parent #node#'
9 9 changesetchild = '# Child #node#'
10 10 filenodelink = ''
11 filerevision = '#rawfileheader##raw#'
12 11 fileline = '#line#'
13 12 diffblock = '#lines#'
14 13 filediff = filediff.tmpl
General Comments 0
You need to be logged in to leave comments. Login now