mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
parent
a6afc21aba
commit
b463f60158
5 changed files with 39 additions and 1 deletions
|
|
@ -83,6 +83,9 @@ CONFIG_OPTIONS = (
|
|||
ConfigOption("allow_sql", True, """
|
||||
Allow arbitrary SQL queries via ?sql= parameter
|
||||
""".strip()),
|
||||
ConfigOption("default_cache_ttl", 365 * 24 * 60 * 60, """
|
||||
Default HTTP cache TTL (used in Cache-Control: max-age= header)
|
||||
""".strip()),
|
||||
)
|
||||
DEFAULT_CONFIG = {
|
||||
option.name: option.default
|
||||
|
|
|
|||
|
|
@ -257,7 +257,17 @@ class BaseView(RenderMixin):
|
|||
r.status = status_code
|
||||
# Set far-future cache expiry
|
||||
if self.ds.cache_headers:
|
||||
r.headers["Cache-Control"] = "max-age={}".format(365 * 24 * 60 * 60)
|
||||
ttl = request.args.get("_ttl", None)
|
||||
if ttl is None or not ttl.isdigit():
|
||||
ttl = self.ds.config["default_cache_ttl"]
|
||||
else:
|
||||
ttl = int(ttl)
|
||||
if ttl == 0:
|
||||
ttl_header = 'no-cache'
|
||||
else:
|
||||
ttl_header = 'max-age={}'.format(ttl)
|
||||
r.headers["Cache-Control"] = ttl_header
|
||||
r.headers["Referrer-Policy"] = "no-referrer"
|
||||
return r
|
||||
|
||||
async def custom_sql(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue