1
2
3
4
5
6
7
8
9
10
11
12
13
14 """ FileGzipper
15
16 A monkey patch that enables gzip compression on static files
17
18 """
19
20 from Products.CMFCore.utils import _setCacheHeaders, _ViewEmulator
21 from Products.CMFCore.utils import _checkConditionalGET
22 from DateTime import DateTime
23 from webdav.common import rfc1123_date
24 from Products.CMFCore.FSFile import FSFile
25 from Products.CMFCore.FSImage import FSImage
27 """
28 The default view of the contents of a File or Image.
29
30 Returns the contents of the file or image. Also, sets the
31 Content-Type HTTP header to the objects content type.
32 """
33 self._updateFromFS()
34 view = _ViewEmulator().__of__(self)
35
36
37
38 if _checkConditionalGET(view, extra_context={}):
39 return ''
40
41
42
43 if ";" not in self.content_type:
44 self.content_type += "; charset=utf-8"
45
46 RESPONSE.setHeader('Content-Type', self.content_type)
47
48
49
50 if self._setOldCacheHeaders():
51
52 _setCacheHeaders(view, extra_context={})
53 return ''
54
55 data = self._readFile(0)
56 data_len = len(data)
57 RESPONSE.setHeader('Content-Length', data_len)
58
59
60
61 RESPONSE.enableHTTPCompression(force=1)
62
63
64
65
66
67 if self.ZCacheable_getManager() is not None:
68 self.ZCacheable_set(None)
69 else:
70 _setCacheHeaders(view, extra_context={})
71 return data
72
73 FSFile.index_html = index_html
74 FSImage.index_html = index_html
75