summaryrefslogtreecommitdiff
path: root/pypi.wsgi
diff options
context:
space:
mode:
Diffstat (limited to 'pypi.wsgi')
-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):