Skip to content

Commit

Permalink
remove router_middleware function (dead code) (#439)
Browse files Browse the repository at this point in the history
* remove dead code

* update changelog
  • Loading branch information
geospatial-jeff authored Aug 1, 2022
1 parent fa658f7 commit c535aca
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 28 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
29 changes: 1 addition & 28 deletions stac_fastapi/api/stac_fastapi/api/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit c535aca

Please sign in to comment.