Skip to content

Commit

Permalink
update from main
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentsarago committed Aug 29, 2024
2 parents 59fd029 + d353b9d commit 2f20440
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* add `/collections/{collection_id}/items/{item_id}/assets/{asset_id}` optional endpoints (`TITILER_PGSTAC_API_ENABLE_ASSETS_ENDPOINTS=TRUE|FALSE`)
* add `/external` optional endpoints (`TITILER_PGSTAC_API_ENABLE_EXTERNAL_DATASET_ENDPOINTS=TRUE|FALSE`)
* add `cachecontrol_exclude_paths` attribute in `ApiSettings` to let users decide if some path should not have cache-control headers (defaults is to exclude `/list`)

## 1.3.1 (2024-08-01)

Expand Down
13 changes: 13 additions & 0 deletions tests/test_searches.py
Original file line number Diff line number Diff line change
Expand Up @@ -1043,3 +1043,16 @@ def test_query_point_searches(app, search_no_bbox, search_bbox):
)

assert response.status_code == 204 # (no content)


def test_cache_middleware_settings(app, search_no_bbox):
"""Make sure some endpoints do not have cache-control headers."""
response = app.get("/searches/list")
assert response.status_code == 200
assert not response.headers.get("Cache-Control")

response = app.get(
f"/searches/{search_no_bbox}/point/-85.5,36.1624", params={"assets": "cog"}
)
assert response.status_code == 200
assert response.headers.get("Cache-Control")
6 changes: 5 additions & 1 deletion titiler/pgstac/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ async def lifespan(app: FastAPI):
allow_headers=["*"],
)

app.add_middleware(CacheControlMiddleware, cachecontrol=settings.cachecontrol)
app.add_middleware(
CacheControlMiddleware,
cachecontrol=settings.cachecontrol,
exclude_path=settings.cachecontrol_exclude_paths,
)

optional_headers = []
if settings.debug:
Expand Down
7 changes: 6 additions & 1 deletion titiler/pgstac/settings.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""API settings."""

from functools import lru_cache
from typing import Any, Optional
from typing import Any, Optional, Set

from pydantic import (
Field,
Expand All @@ -20,6 +20,11 @@ class ApiSettings(BaseSettings):
name: str = "titiler-pgstac"
cors_origins: str = "*"
cachecontrol: str = "public, max-age=3600"
cachecontrol_exclude_paths: Set[str] = Field(
default={
".+/list",
}
)
root_path: str = ""
debug: bool = False

Expand Down

0 comments on commit 2f20440

Please sign in to comment.