def _etag_is_valid(image_attrs, check_etag, is_original): """ Returns a tuple of (True, last_modified_time) if the current ETag for the image described by image_attrs matches the given ETag. Returns (False, new_modified_time) if the current ETag value is different. """ modified_time = image_engine.get_image_original_modified_time(image_attrs) \ if is_original else \ image_engine.get_image_modified_time(image_attrs) if modified_time == 0: # Return False to re-generate the image and re-store the modified time return (False, 0) current_etag = etag( str(modified_time), image_attrs.get_cache_key() ) return ((current_etag == check_etag), modified_time)
def _add_http_caching_headers(response, image_attrs, last_modified_time, expiry_seconds): """ Sets the standard client-side cache control headers expected for an HTTP 200 or 304 response. The last modified time should be given as number of seconds since the epoch. The expiry time is as described for ImageWrapper. """ # This (and others below) auto-converted to correct format by Werkzeug response.date = time.time() if expiry_seconds != 0: if expiry_seconds > 0: response.cache_control.public = True response.cache_control.max_age = expiry_seconds response.expires = int(time.time() + expiry_seconds) else: response.cache_control.public = True response.cache_control.no_cache = True response.expires = 0 if expiry_seconds >= 0: response.headers['ETag'] = etag( str(last_modified_time), image_attrs.get_cache_key() )