##// END OF EJS Templates
file-store: use our own logic for setting content-type. This solves a problem...
marcink -
r4237:490fbd1d stable
parent child Browse files
Show More
@@ -33,6 +33,7 b' from rhodecode.lib import audit_logger'
33 33 from rhodecode.lib.auth import (
34 34 CSRFRequired, NotAnonymous, HasRepoPermissionAny, HasRepoGroupPermissionAny,
35 35 LoginRequired)
36 from rhodecode.lib.vcs.conf.mtypes import get_mimetypes_db
36 37 from rhodecode.model.db import Session, FileStore, UserApiKeys
37 38
38 39 log = logging.getLogger(__name__)
@@ -46,6 +47,15 b' class FileStoreView(BaseAppView):'
46 47 self.storage = utils.get_file_storage(self.request.registry.settings)
47 48 return c
48 49
50 def _guess_type(self, file_name):
51 """
52 Our own type guesser for mimetypes using the rich DB
53 """
54 if not hasattr(self, 'db'):
55 self.db = get_mimetypes_db()
56 _content_type, _encoding = self.db.guess_type(file_name, strict=False)
57 return _content_type, _encoding
58
49 59 def _serve_file(self, file_uid):
50 60
51 61 if not self.storage.exists(file_uid):
@@ -92,10 +102,18 b' class FileStoreView(BaseAppView):'
92 102 FileStore.bump_access_counter(file_uid)
93 103
94 104 file_path = self.storage.store_path(file_uid)
95 return FileResponse(file_path)
105 content_type = 'application/octet-stream'
106 content_encoding = None
107
108 _content_type, _encoding = self._guess_type(file_path)
109 if _content_type:
110 content_type = _content_type
111
96 112 # For file store we don't submit any session data, this logic tells the
97 113 # Session lib to skip it
98 114 setattr(self.request, '_file_response', True)
115 return FileResponse(file_path, request=self.request,
116 content_type=content_type, content_encoding=content_encoding)
99 117
100 118 @LoginRequired()
101 119 @NotAnonymous()
@@ -18,6 +18,19 b''
18 18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 20
21 DEFAULTS = {
22 'encodings_map': {'.gz': 'gzip',
23 '.Z': 'compress',
24 '.bz2': 'bzip2',
25 '.xz': 'xz'},
26 'suffix_map': {'.svgz': '.svg.gz',
27 '.tgz': '.tar.gz',
28 '.taz': '.tar.gz',
29 '.tz': '.tar.gz',
30 '.tbz2': '.tar.bz2',
31 '.txz': '.tar.xz'},
32 }
33
21 34 TYPES_MAP = [
22 35 {'.jpg': 'image/jpg',
23 36 '.mid': 'audio/midi',
@@ -1203,4 +1216,6 b' def get_mimetypes_db(extra_types=None):'
1203 1216 types_map[1].update(extra_types)
1204 1217 db = mimetypes.MimeTypes()
1205 1218 db.types_map = types_map
1219 db.encodings_map.update(DEFAULTS['encodings_map'])
1220 db.suffix_map.update(DEFAULTS['suffix_map'])
1206 1221 return db
General Comments 0
You need to be logged in to leave comments. Login now