diff --git a/doc/configuration.md b/doc/configuration.md index 6b3785c5..4b6137c3 100644 --- a/doc/configuration.md +++ b/doc/configuration.md @@ -85,3 +85,4 @@ The following are reserved configuration variables that modify Appier Extras beh | Name | Type | Description | | ----- | ----- | ----- | | **PREFLIGHT_DATA** | `str` | The default data for the response to be returned to the `OPTIONS` request (defaults to ``). | +| **PREFLIGHT_MAX_AGE** | `int` | The number of seconds to be used in cache infvalication for the `Cache-Control` headers to be returned to the `OPTIONS` request (defaults to `86400`). | diff --git a/src/appier_extras/parts/preflight/part.py b/src/appier_extras/parts/preflight/part.py index c91c777a..5a32130e 100644 --- a/src/appier_extras/parts/preflight/part.py +++ b/src/appier_extras/parts/preflight/part.py @@ -46,6 +46,7 @@ class PreflightPart(appier.Part): def __init__(self, *args, **kwargs): appier.Part.__init__(self, *args, **kwargs) self.data = appier.conf("PREFLIGHT_DATA", "") + self.max_age = appier.conf("PREFLIGHT_MAX_AGE", 86400, cast = int) self.data_b = appier.legacy.bytes(self.data, force = True) def version(self): @@ -66,4 +67,5 @@ def _handler(self): if self.owner.request.handled: return allow_headers = self.request.get_header("Access-Control-Request-Headers", None) if allow_headers: self.request.set_header("Access-Control-Allow-Headers", allow_headers) + self.request.set_cache_control("public, max-age=%d" % self.max_age) self.owner.request.handle(self.data_b)