Skip to content

Commit c535aca

Browse files
remove router_middleware function (dead code) (#439)
* remove dead code * update changelog
1 parent fa658f7 commit c535aca

File tree

2 files changed

+2
-28
lines changed

2 files changed

+2
-28
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* Make item geometry and bbox nullable in sqlalchemy backend. ([#398](https://github.com/stac-utils/stac-fastapi/pull/398))
2525

2626
### Removed
27+
* Remove the unused `router_middleware` function ([#439](https://github.com/stac-utils/stac-fastapi/pull/439))
2728

2829
### Fixed
2930

stac_fastapi/api/stac_fastapi/api/middleware.py

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,11 @@
22

33
import re
44
from http.client import HTTP_PORT, HTTPS_PORT
5-
from typing import Callable, List, Tuple
5+
from typing import List, Tuple
66

7-
from fastapi import APIRouter, FastAPI
8-
from starlette.middleware.base import BaseHTTPMiddleware
9-
from starlette.requests import Request
10-
from starlette.routing import Match
117
from starlette.types import ASGIApp, Receive, Scope, Send
128

139

14-
def router_middleware(app: FastAPI, router: APIRouter):
15-
"""Add middleware to a specific router, assumes no router prefix."""
16-
17-
def deco(func: Callable) -> Callable:
18-
async def _middleware(request: Request, call_next):
19-
# Check if scopes match
20-
matches = any(
21-
[
22-
route.matches(request.scope)[0] == Match.FULL
23-
for route in router.routes
24-
]
25-
)
26-
if matches: # Run the middleware if they do
27-
return await func(request, call_next)
28-
else: # Otherwise skip the middleware
29-
return await call_next(request)
30-
31-
app.add_middleware(BaseHTTPMiddleware, dispatch=_middleware)
32-
return func
33-
34-
return deco
35-
36-
3710
class ProxyHeaderMiddleware:
3811
"""
3912
Account for forwarding headers when deriving base URL.

0 commit comments

Comments
 (0)