Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove router_middleware function (dead code) #439

Merged
merged 2 commits into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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