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