diff --git a/lib/cachecontrol/controller.py b/lib/cachecontrol/controller.py index bb27fbaf..43b3b49a 100644 --- a/lib/cachecontrol/controller.py +++ b/lib/cachecontrol/controller.py @@ -185,6 +185,17 @@ class CacheController(object): if resp.status_code not in [200, 203]: return + # If we want to cache sites not setup with cache headers then add the proper headers and keep the response + if self.cache_all and getattr(resp.headers, 'cache-control', None) is None: + headers = {'Cache-Control': 'public,max-age=%d' % int(900)} + resp.headers.update(headers) + + if getattr(resp.headers, 'expires', None) is None: + expires = datetime.datetime.utcnow() + datetime.timedelta(days=(1)) + expires = expires.strftime("%a, %d %b %Y %H:%M:%S GMT") + headers = {'Expires': expires} + resp.headers.update(headers) + cc_req = self.parse_cache_control(request.headers) cc = self.parse_cache_control(resp.headers) @@ -199,20 +210,6 @@ class CacheController(object): if self.cache_etags and 'etag' in resp.headers: self.cache.set(cache_url, resp) - # If we want to cache sites not setup with cache headers then add the proper headers and keep the response - elif self.cache_all and getattr(resp.headers, 'cache-control', None) is None: - headers = {'Cache-Control': 'public,max-age=%d' % int(3600)} - resp.headers.update(headers) - - if getattr(resp.headers, 'expires', None) is None: - expires = datetime.datetime.utcnow() + datetime.timedelta(days=(25 * 365)) - expires = expires.strftime("%a, %d %b %Y %H:%M:%S GMT") - headers = {'Expires': expires} - resp.headers.update(headers) - - # Add resp to cache - self.cache.set(cache_url, resp) - # Add to the cache if the response headers demand it. If there # is no date header then we can't do anything about expiring # the cache.