def index_html(self, REQUEST, RESPONSE): """ The default view of the contents of a File or Image. Returns the contents of the file or image. Also, sets the Content-Type HTTP header to the objects content type. """ self._updateFromFS() view = _ViewEmulator().__of__(self) # If we have a conditional get, set status 304 and return # no content if _checkConditionalGET(view, extra_context={}): return '' RESPONSE.setHeader('Content-Type', self.content_type) # old-style If-Modified-Since header handling. if self._setOldCacheHeaders(): # Make sure the CachingPolicyManager gets a go as well _setCacheHeaders(view, extra_context={}) return '' data = self._readFile(0) data_len = len(data) RESPONSE.setHeader('Content-Length', data_len) #There are 2 Cache Managers which can be in play.... #need to decide which to use to determine where the cache headers #are decided on. if self.ZCacheable_getManager() is not None: self.ZCacheable_set(None) else: _setCacheHeaders(view, extra_context={}) return data
def ZCache_set(self, ob, data, view_name, keywords, mtime_func): """ An object is pushed into the cache Even though this cache implementation does not cache anything per se, this method is used as a suitable hook to activate the real heavy lifting done by the CachePolicyManager. """ if ob.meta_type not in VIEW_METATYPES: ob = _ViewEmulator().__of__(ob) return _setCacheHeaders(ob, extra_context={})
def index_html(self, REQUEST, RESPONSE): """ The default view of the contents of a File or Image. Returns the contents of the file or image. Also, sets the Content-Type HTTP header to the objects content type. """ self._updateFromFS() data = self._readFile(0) data_len = len(data) last_mod = self._file_mod_time status = 200 # HTTP If-Modified-Since header handling. header=REQUEST.get_header('If-Modified-Since', None) if header is not None: header = header.split(';')[0] # Some proxies seem to send invalid date strings for this # header. If the date string is not valid, we ignore it # rather than raise an error to be generally consistent # with common servers such as Apache (which can usually # understand the screwy date string as a lucky side effect # of the way they parse it). try: mod_since=long(DateTime(header).timeTime()) except: mod_since=None if mod_since is not None: if last_mod > 0 and last_mod <= mod_since: status = 304 data = '' #Last-Modified will get stomped on by a cache policy it there is #one set.... RESPONSE.setStatus(status) RESPONSE.setHeader('Last-Modified', rfc1123_date(last_mod)) RESPONSE.setHeader('Content-Type', self.content_type) if status != 304: # Avoid setting content-length for a 304. See RFC 2616. # Zope might still, for better or for worse, set a # content-length header with value "0". RESPONSE.setHeader('Content-Length', data_len) #There are 2 Cache Managers which can be in play.... #need to decide which to use to determine where the cache headers #are decided on. if self.ZCacheable_getManager() is not None: self.ZCacheable_set(None) else: _setCacheHeaders(_ViewEmulator().__of__(self), extra_context={}) return data
def index_html(self, REQUEST, RESPONSE): """ The default view of the contents of a File or Image. Returns the contents of the file or image. Also, sets the Content-Type HTTP header to the objects content type. """ self._updateFromFS() data = self._data # HTTP If-Modified-Since header handling. header = REQUEST.get_header('If-Modified-Since', None) if header is not None: header = string.split(header, ';')[0] # Some proxies seem to send invalid date strings for this # header. If the date string is not valid, we ignore it # rather than raise an error to be generally consistent # with common servers such as Apache (which can usually # understand the screwy date string as a lucky side effect # of the way they parse it). try: mod_since = long(DateTime(header).timeTime()) except: mod_since = None if mod_since is not None: last_mod = self._file_mod_time if last_mod > 0 and last_mod <= mod_since: # Set header values since apache caching will return # Content-Length of 0 in response if size is not set here RESPONSE.setHeader('Last-Modified', rfc1123_date(last_mod)) RESPONSE.setHeader('Content-Type', self.content_type) RESPONSE.setHeader('Content-Length', len(data)) RESPONSE.setStatus(304) return '' #Last-Modified will get stomped on by a cache policy it there is one set.... RESPONSE.setHeader('Last-Modified', rfc1123_date(self._file_mod_time)) RESPONSE.setHeader('Content-Type', self.content_type) RESPONSE.setHeader('Content-Length', len(data)) #There are 2 Cache Managers which can be in play....need to decide which to use #to determine where the cache headers are decided on. if self.ZCacheable_getManager() is not None: self.ZCacheable_set(None) else: _setCacheHeaders(_ViewEmulator().__of__(self), extra_context={}) return data
def index_html(self, REQUEST, RESPONSE): """ The default view of the contents of a File or Image. Returns the contents of the file or image. Also, sets the Content-Type HTTP header to the objects content type. """ self._updateFromFS() data = self._data # HTTP If-Modified-Since header handling. header=REQUEST.get_header('If-Modified-Since', None) if header is not None: header = header.split(';')[0] # Some proxies seem to send invalid date strings for this # header. If the date string is not valid, we ignore it # rather than raise an error to be generally consistent # with common servers such as Apache (which can usually # understand the screwy date string as a lucky side effect # of the way they parse it). try: mod_since=long(DateTime(header).timeTime()) except: mod_since=None if mod_since is not None: last_mod = self._file_mod_time if last_mod > 0 and last_mod <= mod_since: # Set header values since apache caching will return # Content-Length of 0 in response if size is not set here RESPONSE.setHeader('Last-Modified', rfc1123_date(last_mod)) RESPONSE.setHeader('Content-Type', self.content_type) RESPONSE.setHeader('Content-Length', len(data)) RESPONSE.setStatus(304) return '' #Last-Modified will get stomped on by a cache policy it there is one set.... RESPONSE.setHeader('Last-Modified', rfc1123_date(self._file_mod_time)) RESPONSE.setHeader('Content-Type', self.content_type) RESPONSE.setHeader('Content-Length', len(data)) #There are 2 Cache Managers which can be in play....need to decide which to use #to determine where the cache headers are decided on. if self.ZCacheable_getManager() is not None: self.ZCacheable_set(None) else: _setCacheHeaders(_ViewEmulator().__of__(self), extra_context={}) return data