17
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
from paste import httpexceptions
26
from paste.request import path_info_pop
28
from loggerhead.controllers import TemplatedBranchView
29
from cherrypy import HTTPRedirect, response, session
31
from loggerhead import util
30
34
log = logging.getLogger("loggerhead.controllers")
33
class DownloadUI (TemplatedBranchView):
35
def __call__(self, environ, start_response):
37
class DownloadUI (object):
39
def __init__(self, branch):
45
def default(self, *args, **kw):
36
46
# /download/<rev_id>/<file_id>/[filename]
43
arg = path_info_pop(environ)
48
h = self._branch.get_history()
49
raise httpexceptions.HTTPMovedPermanently(self._branch.url(
51
raise HTTPRedirect(self._branch.url('/changes'))
52
53
revid = h.fix_revid(args[0])
54
path, filename, content = h.get_file(file_id, revid)
55
filename, content = h.get_file(file_id, revid)
55
56
mime_type, encoding = mimetypes.guess_type(filename)
56
57
if mime_type is None:
57
58
mime_type = 'application/octet-stream'
59
self.log.info('/download %s @ %s (%d bytes)',
63
encoded_filename = urllib.quote(filename.encode('utf-8'))
65
('Content-Type', mime_type),
66
('Content-Length', len(content)),
67
('Content-Disposition',
68
'attachment; filename*=utf-8\'\'%s' % encoded_filename),
70
start_response('200 OK', headers)
60
response.headers['Content-Type'] = mime_type
61
response.headers['Content-Length'] = len(content)
62
response.body = content