24
24
from paste import httpexceptions
25
25
from paste.request import path_info_pop
27
from loggerhead.controllers import TemplatedBranchView
29
27
log = logging.getLogger("loggerhead.controllers")
32
class DownloadUI (TemplatedBranchView):
34
def __call__(self, environ, start_response):
30
class DownloadUI (object):
32
def __init__(self, branch):
37
def default(self, request, response):
35
38
# /download/<rev_id>/<file_id>/[filename]
41
arg = path_info_pop(environ)
47
raise httpexceptions.HTTPMovedPermanently(
48
self._branch.absolute_url('/changes'))
50
revid = h.fix_revid(args[0])
52
path, filename, content = h.get_file(file_id, revid)
53
mime_type, encoding = mimetypes.guess_type(filename)
55
mime_type = 'application/octet-stream'
57
self.log.info('/download %s @ %s (%d bytes)',
61
encoded_filename = urllib.quote(filename.encode('utf-8'))
63
('Content-Type', mime_type),
64
('Content-Length', str(len(content))),
65
('Content-Disposition',
66
"attachment; filename*=utf-8''%s" % (encoded_filename,)),
68
start_response('200 OK', headers)
40
h = self._branch.history
46
arg = path_info_pop(request.environ)
52
raise httpexceptions.HTTPMovedPermanently(self._branch.url('../changes'))
54
revid = h.fix_revid(args[0])
56
path, filename, content = h.get_file(file_id, revid)
57
mime_type, encoding = mimetypes.guess_type(filename)
59
mime_type = 'application/octet-stream'
61
self.log.info('/download %s @ %s (%d bytes)', path, h.get_revno(revid), len(content))
62
response.headers['Content-Type'] = mime_type
63
response.headers['Content-Length'] = len(content)
64
response.headers['Content-Disposition'] = 'attachment; filename=%s'%(filename,)
65
response.write(content)