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 DateTime import DateTime
22 from webdav.common import rfc1123_date
23 from Products.CMFCore.FSFile import FSFile
25 """ Modified default view for files to enable
26 gzip compression on js and css files.
27 """
28 self._updateFromFS()
29 data = self._readFile(0)
30 data_len = len(data)
31 last_mod = self._file_mod_time
32 status = 200
33
34 header=REQUEST.get_header('If-Modified-Since', None)
35 if header is not None:
36 header = header.split(';')[0]
37 try:
38 mod_since=long(DateTime(header).timeTime())
39 except:
40 mod_since=None
41
42 if mod_since is not None:
43 if last_mod > 0 and last_mod <= mod_since:
44 status = 304
45 data = ''
46 RESPONSE.setStatus(status)
47 RESPONSE.setHeader('Last-Modified', rfc1123_date(last_mod))
48 RESPONSE.setHeader('Content-Type', self.content_type)
49
50
51 RESPONSE.enableHTTPCompression(force=1)
52
53 if status != 304:
54 RESPONSE.setHeader('Content-Length', data_len)
55 if self.ZCacheable_getManager() is not None:
56 self.ZCacheable_set(None)
57 else:
58 _setCacheHeaders(_ViewEmulator().__of__(self), extra_context={})
59 return data
60
61 FSFile.index_html = index_html
62