Skip to content

Commit

Permalink
Adds cache control to AgencyApp
Browse files Browse the repository at this point in the history
  • Loading branch information
Tschuppi81 committed Dec 1, 2023
1 parent 0af598b commit 6a0e232
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/onegov/agency/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from onegov.agency.theme import AgencyTheme
from onegov.api import ApiApp
from onegov.core import utils
from onegov.core.framework import transaction_tween_factory
from onegov.org import OrgApp
from onegov.org.app import get_editor_asset as editor_assets
from onegov.org.app import get_i18n_localedirs as get_org_i18n_localedirs
Expand Down Expand Up @@ -169,3 +170,28 @@ def get_api_endpoints():
PersonApiEndpoint,
MembershipApiEndpoint
]


@AgencyApp.tween_factory(
over=transaction_tween_factory
)
def cache_control_tween_factory(
app: AgencyApp,
handler: 'Callable[[AgencyRequest], Response]'
) -> 'Callable[[AgencyRequest], Response]':

def cache_control_tween(request: AgencyRequest) -> 'Response':
""" Set headers and cookies for cache control.
Makes sure, pages are not cached downstream when logged in by setting
the cache-control header accordingly.
"""

response = handler(request)
if request.is_logged_in:
response.headers.add('cache-control', 'no-store')

return response

return cache_control_tween

0 comments on commit 6a0e232

Please sign in to comment.