From c535acae74259d9db5ad26b7034eb3950fee491d Mon Sep 17 00:00:00 2001 From: Jeff Albrecht Date: Mon, 1 Aug 2022 16:20:42 -0600 Subject: [PATCH] remove `router_middleware` function (dead code) (#439) * remove dead code * update changelog --- CHANGES.md | 1 + .../api/stac_fastapi/api/middleware.py | 29 +------------------ 2 files changed, 2 insertions(+), 28 deletions(-) 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 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.