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