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

# Source Code for Module Products.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 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
    26 -def index_html(self, REQUEST, RESPONSE):
    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      # If we have a conditional get, set status 304 and return
    37      # no content
    38      if _checkConditionalGET(view, extra_context={}):
    39          return ''
    40
    41      ###### ZENOSS PATCH #####
    42      # Patch to ensure a static charset
    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      # old-style If-Modified-Since header handling.
    50      if self._setOldCacheHeaders():
    51          # Make sure the CachingPolicyManager gets a go as well
    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      ###### ZENOSS PATCH #####
    60      # Patch to use gzip compression
    61      RESPONSE.enableHTTPCompression(force=1)
    62      #########################
    63
    64      #There are 2 Cache Managers which can be in play....
    65      #need to decide which to use to determine where the cache headers
    66      #are decided on.
    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