99
1010import httpx
1111from pydantic import HttpUrl
12+ from starlette .datastructures import Headers
1213from starlette .requests import Request
1314from starlette .types import ASGIApp
1415
@@ -36,6 +37,8 @@ class AuthenticationExtensionMiddleware(JsonResponseMiddleware):
3637 "https://stac-extensions.github.io/authentication/v1.1.0/schema.json"
3738 )
3839
40+ json_content_type_expr : str = r"application/json|geo\+json)"
41+
3942 def __post_init__ (self ):
4043 """Load after initialization."""
4144 if self .oidc_config_url and not self .auth_scheme :
@@ -56,15 +59,23 @@ def __post_init__(self):
5659 },
5760 }
5861
59- def should_transform_response (self , request : Request ) -> bool :
62+ def should_transform_response (
63+ self , request : Request , response_headers : Headers
64+ ) -> bool :
6065 """Determine if the response should be transformed."""
6166 # Match STAC catalog, collection, or item URLs with a single regex
62- return bool (
63- re .match (
64- # catalog, collections, collection, items, item, search
65- r"^(/|/collections(/[^/]+(/items(/[^/]+)?)?)?|/search)$" ,
66- request .url .path ,
67- )
67+ return all (
68+ [
69+ re .match (
70+ # catalog, collections, collection, items, item, search
71+ r"^(/|/collections(/[^/]+(/items(/[^/]+)?)?)?|/search)$" ,
72+ request .url .path ,
73+ ),
74+ re .match (
75+ self .json_content_type_expr ,
76+ response_headers .get ("content-type" , "" ),
77+ ),
78+ ]
6879 )
6980
7081 def transform_json (self , doc : dict [str , Any ]) -> dict [str , Any ]:
0 commit comments