From dca367e8ce8519862e98e862d7149fdd2968a987 Mon Sep 17 00:00:00 2001 From: geospatial-jeff Date: Mon, 1 Aug 2022 16:10:00 -0600 Subject: [PATCH 1/2] remove dead code --- .../api/stac_fastapi/api/middleware.py | 29 +------------------ 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/stac_fastapi/api/stac_fastapi/api/middleware.py b/stac_fastapi/api/stac_fastapi/api/middleware.py index fe01de629..9803e7ab0 100644 --- a/stac_fastapi/api/stac_fastapi/api/middleware.py +++ b/stac_fastapi/api/stac_fastapi/api/middleware.py @@ -2,38 +2,11 @@ import re from http.client import HTTP_PORT, HTTPS_PORT -from typing import Callable, List, Tuple +from typing import List, Tuple -from fastapi import APIRouter, FastAPI -from starlette.middleware.base import BaseHTTPMiddleware -from starlette.requests import Request -from starlette.routing import Match from starlette.types import ASGIApp, Receive, Scope, Send -def router_middleware(app: FastAPI, router: APIRouter): - """Add middleware to a specific router, assumes no router prefix.""" - - def deco(func: Callable) -> Callable: - async def _middleware(request: Request, call_next): - # Check if scopes match - matches = any( - [ - route.matches(request.scope)[0] == Match.FULL - for route in router.routes - ] - ) - if matches: # Run the middleware if they do - return await func(request, call_next) - else: # Otherwise skip the middleware - return await call_next(request) - - app.add_middleware(BaseHTTPMiddleware, dispatch=_middleware) - return func - - return deco - - class ProxyHeaderMiddleware: """ Account for forwarding headers when deriving base URL. From 9744fbe4c772b2a6569eca7bbc8a2bbc621fe06c Mon Sep 17 00:00:00 2001 From: geospatial-jeff Date: Mon, 1 Aug 2022 16:11:55 -0600 Subject: [PATCH 2/2] update changelog --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index f704c7b34..b653aee3f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -24,6 +24,7 @@ * Make item geometry and bbox nullable in sqlalchemy backend. ([#398](https://github.com/stac-utils/stac-fastapi/pull/398)) ### Removed +* Remove the unused `router_middleware` function ([#439](https://github.com/stac-utils/stac-fastapi/pull/439)) ### Fixed