Skip to content

Module stac_fastapi.api.middleware

Api middleware.

Variables

HTTPS_PORT
HTTP_PORT

Classes

CORSMiddleware

class CORSMiddleware(
    app: Callable[[MutableMapping[str, Any], Callable[[], Awaitable[MutableMapping[str, Any]]], Callable[[MutableMapping[str, Any]], Awaitable[NoneType]]], Awaitable[NoneType]],
    allow_origins: Sequence[str] = ('*',),
    allow_methods: Sequence[str] = ('OPTIONS', 'POST', 'GET'),
    allow_headers: Sequence[str] = ('Content-Type',),
    allow_credentials: bool = False,
    allow_origin_regex: Optional[str] = None,
    expose_headers: Sequence[str] = (),
    max_age: int = 600
)

Subclass of Starlette's standard CORS middleware with default values set to those

recommended by the STAC API spec.

github.com/radiantearth/stac-api-spec/blob/914cf8108302e2ec734340080a45aaae4859bb63/implementation.md#cors

Ancestors (in MRO)

  • starlette.middleware.cors.CORSMiddleware

Static methods

allow_explicit_origin

def allow_explicit_origin(
    headers: 'MutableHeaders',
    origin: 'str'
) -> 'None'

Methods

is_allowed_origin

def is_allowed_origin(
    self,
    origin: 'str'
) -> 'bool'

preflight_response

def preflight_response(
    self,
    request_headers: 'Headers'
) -> 'Response'

send

def send(
    self,
    message: 'Message',
    send: 'Send',
    request_headers: 'Headers'
) -> 'None'

simple_response

def simple_response(
    self,
    scope: 'Scope',
    receive: 'Receive',
    send: 'Send',
    request_headers: 'Headers'
) -> 'None'

ProxyHeaderMiddleware

class ProxyHeaderMiddleware(
    app: Callable[[MutableMapping[str, Any], Callable[[], Awaitable[MutableMapping[str, Any]]], Callable[[MutableMapping[str, Any]], Awaitable[NoneType]]], Awaitable[NoneType]]
)

Account for forwarding headers when deriving base URL.

Prioritise standard Forwarded header, look for non-standard X-Forwarded-* if missing. Default to what can be derived from the URL if no headers provided. Middleware updates the host header that is interpreted by starlette when deriving Request.base_url.