Skip to content

Commit

Permalink
Merge pull request #536 from EOxServer/cache-control-headers-for-rend…
Browse files Browse the repository at this point in the history
…erer

Add cache-control header to urls reachable from VS
  • Loading branch information
totycro committed Sep 19, 2022
2 parents e42aad6 + 1ccc28f commit f68343c
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 3 deletions.
44 changes: 44 additions & 0 deletions eoxserver/services/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# ------------------------------------------------------------------------------
#
# Project: EOxServer <http://eoxserver.org>
# Authors: Bernhard Mallinger <bernhard.mallinger@eox.at>
#
# ------------------------------------------------------------------------------
# Copyright (C) 2022 EOX IT Services GmbH
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies of this Software or works derived from this Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
# ------------------------------------------------------------------------------

import typing

from django.conf import settings
from django.views.decorators.cache import cache_control

_cache_time_str = getattr(settings, "EOXS_RENDERER_CACHE_TIME", None)

EOXS_RENDERER_CACHE_TIME: typing.Optional[int] = (
int(_cache_time_str) if _cache_time_str is not None else None
)

def apply_cache_header(view):
return (
cache_control(max_age=EOXS_RENDERER_CACHE_TIME)(view)
if EOXS_RENDERER_CACHE_TIME is not None
else view
)
8 changes: 6 additions & 2 deletions eoxserver/services/opensearch/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,20 @@
except ImportError:
from django.urls import include, re_path

from eoxserver.services.config import apply_cache_header
from eoxserver.services.opensearch.views import description, search


search_cached = apply_cache_header(search)

app_name = 'opensearch'
urlpatterns = [
re_path(r'^$', description, name='description'),
re_path(r'^(?P<format_name>[^/]+)/$', search, name='search'),
re_path(r'^(?P<format_name>[^/]+)/$', search_cached, name='search'),
re_path(r'^collections/(?P<collection_id>[^/]+)/', include(([
re_path(r'^$', description, name='description'),
re_path(
r'^(?P<format_name>[^/]+)/$', search,
r'^(?P<format_name>[^/]+)/$', search_cached,
name='search'
)
], 'collection')))
Expand Down
1 change: 1 addition & 0 deletions eoxserver/services/opensearch/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#-------------------------------------------------------------------------------


from django.conf import settings
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt

Expand Down
3 changes: 2 additions & 1 deletion eoxserver/services/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@
from django.urls import reverse

from eoxserver.services import views
from eoxserver.services.config import apply_cache_header

urlpatterns = [
re_path(r'^$', views.ows, name='ows')
re_path(r'^$', apply_cache_header(views.ows), name='ows',)
]


Expand Down
1 change: 1 addition & 0 deletions eoxserver/services/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import logging
import traceback

from django.conf import settings
from django.http import HttpResponse
try:
from django.http import StreamingHttpResponse
Expand Down

0 comments on commit f68343c

Please sign in to comment.