def GET(self): """Default document""" file = self.chooseContext() request = self.request response = request.response # Control in-memory caching cache_in_memory = file.caching == "memory" if cache_in_memory: last_mod = file.lmt if last_mod > file.data_last_fetched: # force delete file contents file.purgeData() # HTTP If-Modified-Since header handling. This is duplicated # from OFS.Image.Image - it really should be consolidated # somewhere... if __five__: header = request.get_header("If-Modified-Since") else: header = request.getHeader("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(timeFromDateTimeString(header)) except: mod_since = None if mod_since is not None: if not cache_in_memory: last_mod = file.lmt if last_mod > 0 and int(last_mod) <= mod_since: response.setStatus(304) return "" response.setHeader("Content-Type", file.content_type) response.setHeader("Last-Modified", file.lmh) # Cache for one day response.setHeader("Cache-Control", "public,max-age=86400") data = file.data if not cache_in_memory: # force delete file contents file.purgeData() return data
def isModified(self): if self.modified == 0: return True request = self.request header = request.getHeader('IF_MODIFIED_SINCE', None, True) if header is not None: header = header.split(';')[0] try: mod_since=long(timeFromDateTimeString(header)) except: mod_since=None if mod_since is not None: lmt = self.info.modified() if lmt > 0 and lmt <= mod_since: return False return True
def GET(self): """Download the resource if it have been modified. """ header = self.request.environ.get('HTTP_IF_MODIFIED_SINCE', None) if header is not None: header = header.split(';')[0] try: mod_since = long(timeFromDateTimeString(header)) except: mod_since = None if mod_since is not None: last_mod = long(self.context.lmt) if last_mod > 0 and last_mod <= mod_since: self.request.response.setStatus(304) return u'' self.__set_http_headers() return self.context.data()
def GET(self): """Default content""" file = self.context request = self.request response = request.response # HTTP If-Modified-Since header handling. This is duplicated # from OFS.Image.Image - it really should be consolidated # somewhere... header = request.get_header('If-Modified-Since') 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(timeFromDateTimeString(header)) except: mod_since = None if mod_since is not None: if getattr(file, 'lmt', None): last_mod = long(file.lmt) else: last_mod = long(0) if last_mod > 0 and last_mod <= mod_since: response.setStatus(304) return '' response.setHeader('Content-Type', file.content_type) response.setHeader('Last-Modified', file.lmh) # Cache for one day response.setHeader('Cache-Control', 'public,max-age=86400') f = open(file.path, 'rb') data = f.read() f.close() return data
def GET(self): """Default content""" file = self.context request = self.request response = request.response # HTTP If-Modified-Since header handling. This is duplicated # from OFS.Image.Image - it really should be consolidated # somewhere... header = request.environ.get('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(timeFromDateTimeString(header)) except: mod_since=None if mod_since is not None: if getattr(file, 'lmt', None): last_mod = long(file.lmt) else: last_mod = long(0) if last_mod > 0 and last_mod <= mod_since: response.setStatus(304) return '' response.setHeader('Content-Type', file.content_type) response.setHeader('Last-Modified', file.lmh) # Cache for one day response.setHeader('Cache-Control', 'public,max-age=86400') f = open(file.path, 'rb') data = f.read() f.close() return data
def GET(self): request = self.request response = request.response resource = self.resource try: modified = ICMFDublinCore(resource).modified except TypeError: modified = datetime.datetime.now() lmt = long(time.mktime(modified.timetuple())) header = request.getHeader('If-Modified-Since', None) if header is not None: header = header.split(';')[0] try: mod_since=long(timeFromDateTimeString(header)) except: mod_since=None if mod_since is not None: if lmt > 0 and lmt <= mod_since: response.setStatus(304) return '' response.setHeader('Last-Modified', rfc1123_date(lmt)) return resource.render(request, attr=self.attr)