Package ZenWidgets :: Module FileGzipper
[hide private]
[frames] | no frames]

Source Code for Module ZenWidgets.FileGzipper

 1  ########################################################################### 
 2  # 
 3  # This program is part of Zenoss Core, an open source monitoring platform. 
 4  # Copyright (C) 2007, Zenoss Inc. 
 5  # 
 6  # This program is free software; you can redistribute it and/or modify it 
 7  # under the terms of the GNU General Public License version 2 as published by 
 8  # the Free Software Foundation. 
 9  # 
10  # For complete information please visit: http://www.zenoss.com/oss/ 
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 
24 -def index_html(self, REQUEST, RESPONSE):
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 # HTTP If-Modified-Since header handling. 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 # The key line! 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