Пример #1
0
 def cache_expires_in(self, timedelta=timedelta(0)):
     """Sets the Cache-Control header of the response.
     See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9
     Args:
         timedelta - the time this resource can be cached
     """
     self.response.headers["Expires"] = utils.format_http_time(datetime.utcnow() + timedelta)
     self.response.headers["Cache-Control"] = "max-age=%d" % utils.total_seconds(timedelta)
     logging.info("Setting caches to expire after %s" % timedelta)
Пример #2
0
    def handle_if_modified_since(self, last_modified):
        """Checks if the request has the 'If-Modified-Since' header and compares it to the
        last_modified datetime. It also emits the 'Last-Modified' header in all responses. 
        """
        # emit the last-modified header
        self.response.headers["Last-Modified"] = utils.format_http_time(last_modified)

        # if we got the 'if-modified-since header', raise a 304 if the last modified time
        # is before the last-seen time.
        if "If-Modified-Since" in self.request.headers:
            ims = self.request.headers["If-Modified-Since"]
            if utils.parse_http_time(ims) >= last_modified.replace(microsecond=0):
                raise errors.NotModifiedError()
Пример #3
0
 def no_cache(self):
     """Sets the cache headers to no-cache"""
     self.response.headers["Cache-Control"] = "no-cache"
     self.response.headers["Expires"] = utils.format_http_time(datetime(year=1970, month=1, day=1))