From: Krzysztof Tarnowski Date: Fri, 8 Jul 2011 11:40:11 +0000 (+0200) Subject: Add a way of customizing cache control behavior for static files. X-Git-Tag: v2.1.0~78^2~5^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ea2a5cf4ed3afab74f1b4488d526171adfa6929b;p=thirdparty%2Ftornado.git Add a way of customizing cache control behavior for static files. --- diff --git a/tornado/web.py b/tornado/web.py index c5b0ed79d..77482a780 100644 --- a/tornado/web.py +++ b/tornado/web.py @@ -1463,12 +1463,14 @@ class StaticFileHandler(RequestHandler): modified = datetime.datetime.fromtimestamp(stat_result[stat.ST_MTIME]) self.set_header("Last-Modified", modified) - if "v" in self.request.arguments: + + if self.enable_aggressive_caching(path): self.set_header("Expires", datetime.datetime.utcnow() + \ datetime.timedelta(days=365*10)) self.set_header("Cache-Control", "max-age=" + str(86400*365*10)) else: self.set_header("Cache-Control", "public") + mime_type, encoding = mimetypes.guess_type(abspath) if mime_type: self.set_header("Content-Type", mime_type) @@ -1497,6 +1499,10 @@ class StaticFileHandler(RequestHandler): """For subclass to add extra headers to the response""" pass + def enable_aggressive_caching(self, path): + """Override to customize cache control behavior.""" + return "v" in self.request.arguments + class FallbackHandler(RequestHandler): """A RequestHandler that wraps another HTTP server callback.