Skip to content

Commit

Permalink
Merge branch 'master' of github.com:okfn/ckan
Browse files Browse the repository at this point in the history
  • Loading branch information
rufuspollock committed Mar 21, 2012
2 parents 163ea7b + 3b1fff9 commit 590962d
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 712 deletions.
14 changes: 11 additions & 3 deletions ckan/config/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,18 @@ def _start_response(status, response_headers, exc_info=None):
return start_response(status, response_headers, exc_info)

# Only use cache for GET requests
# If there is a cookie we avoid the cache.
# REMOTE_USER is used by some tests.
if environ['REQUEST_METHOD'] != 'GET' or environ.get('HTTP_COOKIE') or \
environ.get('REMOTE_USER'):
if environ['REQUEST_METHOD'] != 'GET' or environ.get('REMOTE_USER'):
return self.app(environ, start_response)

# If there is a ckan cookie (or auth_tkt) we avoid the cache.
# We want to allow other cookies like google analytics ones :(
cookie_string = environ.get('HTTP_COOKIE')
if cookie_string:
for cookie in cookie_string.split(';'):
if cookie.startswith('ckan') or cookie.startswith('auth_tkt'):
return self.app(environ, start_response)

# Make our cache key
key = 'page:%s?%s' % (environ['PATH_INFO'], environ['QUERY_STRING'])

Expand All @@ -220,6 +226,8 @@ def _start_response(status, response_headers, exc_info=None):
self.redis_connection = self.redis.StrictRedis()
self.redis_connection.flushdb()
except self.redis_exception:
# Connection may have failed at flush so clear it.
self.redis_connection = None
return self.app(environ, start_response)

# If cached return cached result
Expand Down
15 changes: 11 additions & 4 deletions ckan/lib/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,17 +180,24 @@ def __call__(self, environ, start_response):
# the request is routed to. This routing information is
# available in environ['pylons.routes_dict']

# clean out any old cookies as they may contain api keys etc
# Clean out any old cookies as they may contain api keys etc
# This also improves the cachability of our pages as cookies
# prevent proxy servers from caching content unless they have
# been configured to ignore them.
for cookie in request.cookies:
if cookie.startswith('ckan') and cookie not in ['ckan', 'ckan_killtopbar']:
if cookie.startswith('ckan') and cookie not in ['ckan']:
response.delete_cookie(cookie)

if cookie == 'ckan' and not c.user and not h.are_there_flash_messages():
# Remove the ckan session cookie if not used e.g. logged out
elif cookie == 'ckan' and not c.user and not h.are_there_flash_messages():
if session.id:
if not session.get('lang'):
session.delete()
else:
response.delete_cookie(cookie)
# Remove auth_tkt repoze.who cookie if user not logged in.
elif cookie == 'auth_tkt' and not session.id:
response.delete_cookie(cookie)

try:
return WSGIController.__call__(self, environ, start_response)
finally:
Expand Down
Empty file.

0 comments on commit 590962d

Please sign in to comment.