Skip to content

Commit

Permalink
Better cache control (more efficient)
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed May 27, 2019
1 parent 572d997 commit 139b641
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/configuration.md
Expand Up @@ -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`). |
2 changes: 2 additions & 0 deletions src/appier_extras/parts/preflight/part.py
Expand Up @@ -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):
Expand All @@ -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)

0 comments on commit 139b641

Please sign in to comment.