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