Skip to content

Commit 1ded110

Browse files
feature: deprecated vendored CORSMiddleware (#882)
* feature: remove vendoring of CORSMiddleware * update changelog
1 parent 600b653 commit 1ded110

3 files changed

Lines changed: 31 additions & 9 deletions

File tree

‎CHANGES.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
## [Unreleased]
44

5+
### Fixed
6+
7+
- swap usage of vendored `CORSMiddleware` for the official one from starlette
8+
- add deprecatation warning for `stac_fastapi.api.middleware.CORSMiddleware`
9+
510
## [6.2.0] - 2026-01-13
611

712
### Removed

‎stac_fastapi/api/stac_fastapi/api/app.py‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
from stac_pydantic.shared import MimeTypes
1414
from stac_pydantic.version import STAC_VERSION
1515
from starlette.middleware import Middleware
16+
from starlette.middleware.cors import CORSMiddleware
1617
from starlette.responses import Response
1718

1819
from stac_fastapi.api.errors import DEFAULT_STATUS_CODES, add_exception_handlers
19-
from stac_fastapi.api.middleware import CORSMiddleware, ProxyHeaderMiddleware
20+
from stac_fastapi.api.middleware import ProxyHeaderMiddleware
2021
from stac_fastapi.api.models import (
2122
APIRequest,
2223
CollectionUri,
@@ -126,7 +127,14 @@ class StacApi:
126127
default=attr.Factory(
127128
lambda: [
128129
Middleware(BrotliMiddleware),
129-
Middleware(CORSMiddleware),
130+
Middleware(
131+
CORSMiddleware,
132+
# Set CORS defaults to those recommended by the STAC API spec
133+
allow_origins=["*"],
134+
allow_methods=["OPTIONS", "POST", "GET"],
135+
allow_headers=["Content-Type"],
136+
max_age=600,
137+
),
130138
Middleware(ProxyHeaderMiddleware),
131139
]
132140
)

‎stac_fastapi/api/stac_fastapi/api/middleware.py‎

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import contextlib
44
import re
55
import typing
6+
import warnings
67
from http.client import HTTP_PORT, HTTPS_PORT
78
from typing import List, Optional, Tuple
89

@@ -31,17 +32,25 @@ def __init__(
3132
allow_origin_regex: typing.Optional[str] = None,
3233
expose_headers: typing.Sequence[str] = (),
3334
max_age: int = 600,
35+
**kwargs: typing.Any,
3436
) -> None:
3537
"""Create CORS middleware."""
38+
warnings.warn(
39+
"""stac_fastapi.api.middleware.CORSMiddleware is deprecated and
40+
will be removed in a future release.
41+
Please use starlette.middleware.cors.CORSMiddleware instead.""",
42+
DeprecationWarning,
43+
)
3644
super().__init__(
3745
app,
38-
allow_origins,
39-
allow_methods,
40-
allow_headers,
41-
allow_credentials,
42-
allow_origin_regex,
43-
expose_headers,
44-
max_age,
46+
allow_origins=allow_origins,
47+
allow_methods=allow_methods,
48+
allow_headers=allow_headers,
49+
allow_credentials=allow_credentials,
50+
allow_origin_regex=allow_origin_regex,
51+
expose_headers=expose_headers,
52+
max_age=max_age,
53+
**kwargs,
4554
)
4655

4756

0 commit comments

Comments
 (0)