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 Products.CMFCore.FSFile import FSFile
23 from Products.CMFCore.FSImage import FSImage
25 """
26 The default view of the contents of a File or Image.
27
28 Returns the contents of the file or image. Also, sets the
29 Content-Type HTTP header to the objects content type.
30 """
31 self._updateFromFS()
32 view = _ViewEmulator().__of__(self)
33
34
35
36 if _checkConditionalGET(view, extra_context={}):
37 return ''
38
39
40
41 if ";" not in self.content_type:
42 self.content_type += "; charset=utf-8"
43
44 RESPONSE.setHeader('Content-Type', self.content_type)
45
46
47
48 if self._setOldCacheHeaders():
49
50 _setCacheHeaders(view, extra_context={})
51 return ''
52
53 data = self._readFile(0)
54 data_len = len(data)
55 RESPONSE.setHeader('Content-Length', data_len)
56
57
58
59 RESPONSE.enableHTTPCompression(REQUEST)
60
61
62
63
64
65 if self.ZCacheable_getManager() is not None:
66 self.ZCacheable_set(None)
67 else:
68 _setCacheHeaders(view, extra_context={})
69 return data
70
71 FSFile.index_html = index_html
72 FSImage.index_html = index_html
73
74 from zope.browserresource.file import FileResource
75 from Products.ZenUtils.Utils import monkeypatch
76 from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
77
78 @monkeypatch(ViewPageTemplateFile)
79 -def __call__(self, __instance, *args, **keywords):
80 try:
81 response = __instance.request.response
82 response.enableHTTPCompression(REQUEST=__instance.request)
83 except AttributeError:
84 pass
85 return original(self, __instance, *args, **keywords)
86
87 oldget = FileResource.GET
88 @monkeypatch(FileResource)
89 -def GET(self):
92