summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDonald Stufft <donald@stufft.io>2013-06-22 12:47:03 -0400
committerDonald Stufft <donald@stufft.io>2013-06-22 12:47:03 -0400
commit5e3c1e6fb41ac00fa4f74ff2c5950f72277d667c (patch)
tree7ed4d2664153b80cbbc2101fc88d48c487ef1634
parent08a589da873c5178e1118722e03d318fab212779 (diff)
downloaddecorator-5e3c1e6fb41ac00fa4f74ff2c5950f72277d667c.tar.gz
Make a CacheControlMiddleware that adds Cache-Control directives
-rw-r--r--pypi.wsgi23
1 files changed, 23 insertions, 0 deletions
diff --git a/pypi.wsgi b/pypi.wsgi
index 7ed66d6..e40056f 100644
--- a/pypi.wsgi
+++ b/pypi.wsgi
@@ -41,6 +41,25 @@ class Request:
self.start_response(self.status, self.headers)
+class CacheControlMiddleware(object):
+
+ def __init__(self, app):
+ self.app = app
+
+ def __call__(self, environ, start_response):
+
+ def _start_response(status, headers, exc_info=None):
+ script = environ.get("SCRIPT_NAME", None)
+ if script in set(["/simple", "/serversig", "/packages"]):
+ headers += [("Cache-Control", "max-age=86400, public")]
+ else:
+ headers += [("Cache-Control", "private")]
+
+ return start_response(status, headers, exc_info)
+
+ return self.app(environ, _start_response)
+
+
def debug(environ, start_response):
if environ['PATH_INFO'].startswith("/auth") and \
"HTTP_AUTHORIZATION" not in environ:
@@ -68,6 +87,10 @@ def application(environ, start_response):
#application=debug
+# Handle Caching at the WSGI layer
+application = CacheControlMiddleware(application)
+
+
# pretend to be like the UWSGI configuration - set SCRIPT_NAME to the first
# part of the PATH_INFO if it's valid and remove that part from the PATH_INFO
def site_fake(app, environ, start_response):