##// END OF EJS Templates
Use paste fileapp to properly send the archive size
marcink -
r2294:3c1d9917 beta
parent child Browse files
Show More
@@ -32,6 +32,7 b' from pylons import request, response, tm'
32 from pylons.i18n.translation import _
32 from pylons.i18n.translation import _
33 from pylons.controllers.util import redirect
33 from pylons.controllers.util import redirect
34 from pylons.decorators import jsonify
34 from pylons.decorators import jsonify
35 from paste.fileapp import FileApp, _FileIter
35
36
36 from rhodecode.lib import diffs
37 from rhodecode.lib import diffs
37 from rhodecode.lib import helpers as h
38 from rhodecode.lib import helpers as h
@@ -364,20 +365,22 b' class FilesController(BaseRepoController'
364 with open(_archive_name, 'wb') as f:
365 with open(_archive_name, 'wb') as f:
365 cs.fill_archive(stream=f, kind=fileformat, subrepos=subrepos)
366 cs.fill_archive(stream=f, kind=fileformat, subrepos=subrepos)
366
367
367 response.content_type = content_type
368 content_disposition = 'attachment; filename=%s-%s%s' \
368 response.content_disposition = 'attachment; filename=%s-%s%s' \
369 % (repo_name, revision[:12], ext)
369 % (repo_name, revision[:12], ext)
370 response.content_length = str(os.path.getsize(_archive_name))
370 content_length = os.path.getsize(_archive_name)
371
372 headers = [('Content-Disposition', str(content_disposition)),
373 ('Content-Type', str(content_type)),
374 ('Content-Length', str(content_length))]
371
375
372 def get_chunked_archive(tmpfile):
376 class _DestroyingFileWrapper(_FileIter):
373 while True:
377 def close(self):
374 data = tmpfile.read(16 * 1024)
378 self.file.close
375 if not data:
379 os.remove(self.file.name)
376 tmpfile.close()
380
377 os.unlink(tmpfile.name)
381 request.environ['wsgi.file_wrapper'] = _DestroyingFileWrapper
378 break
382 fapp = FileApp(_archive_name, headers=headers)
379 yield data
383 return fapp(request.environ, self.start_response)
380 return get_chunked_archive(tmpfile=open(_archive_name, 'rb'))
381
384
382 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
385 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
383 'repository.admin')
386 'repository.admin')
@@ -199,13 +199,12 b' class TestFilesController(TestController'
199 fname=fname))
199 fname=fname))
200
200
201 self.assertEqual(response.status, '200 OK')
201 self.assertEqual(response.status, '200 OK')
202 self.assertEqual(response.response._headers.items(),
202 heads = [
203 [('Pragma', 'no-cache'),
203 ('Content-Type', 'text/html; charset=utf-8'),
204 ('Cache-Control', 'no-cache'),
204 ('Content-Length', '0'), ('Pragma', 'no-cache'),
205 ('Content-Type', '%s; charset=utf-8' % info[0]),
205 ('Cache-Control', 'no-cache')
206 ('Content-Disposition', 'attachment; filename=%s' % filename),
207 ]
206 ]
208 )
207 self.assertEqual(response.response._headers.items(), heads)
209
208
210 def test_archival_wrong_ext(self):
209 def test_archival_wrong_ext(self):
211 self.log_user()
210 self.log_user()
General Comments 0
You need to be logged in to leave comments. Login now