Skip to content

Commit

Permalink
chore: reorg code
Browse files Browse the repository at this point in the history
  • Loading branch information
alukach committed Dec 8, 2024
1 parent cd64125 commit e6af5a3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
18 changes: 10 additions & 8 deletions src/stac_auth_proxy/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ def create_app(settings: Optional[Settings] = None) -> FastAPI:
"""FastAPI Application Factory."""
settings = settings or Settings()

app = FastAPI(openapi_url=None)
app = FastAPI(
openapi_url=None,
)
app.add_middleware(AddProcessTimeHeaderMiddleware)

auth_scheme = OpenIdConnectAuth(
Expand All @@ -33,6 +35,13 @@ def create_app(settings: Optional[Settings] = None) -> FastAPI:
logger.info("Wrapping auth scheme")
auth_scheme = settings.guard(auth_scheme)

if settings.debug:
app.add_api_route(
"/_debug",
lambda: {"settings": settings},
methods=["GET"],
)

proxy_handler = ReverseProxyHandler(upstream=str(settings.upstream_url))
openapi_handler = OpenApiSpecHandler(
proxy=proxy_handler, oidc_config_url=str(settings.oidc_discovery_url)
Expand Down Expand Up @@ -63,13 +72,6 @@ def create_app(settings: Optional[Settings] = None) -> FastAPI:
methods=methods,
)

if settings.debug:
app.add_api_route(
"/_debug",
lambda: {"settings": settings},
methods=["GET"],
)

# Catchall for remainder of the endpoints
app.add_api_route(
"/{path:path}",
Expand Down
9 changes: 5 additions & 4 deletions src/stac_auth_proxy/handlers/reverse_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ async def proxy_request(self, request: Request, *, stream=False) -> httpx.Respon
headers.setdefault("X-Forwarded-Host", request.url.hostname)

# https://github.com/fastapi/fastapi/discussions/7382#discussioncomment-5136466
url = httpx.URL(
path=request.url.path,
query=request.url.query.encode("utf-8"),
)
rp_req = self.client.build_request(
request.method,
url=httpx.URL(
path=request.url.path,
query=request.url.query.encode("utf-8"),
),
url=url,
headers=headers,
content=request.stream(),
)
Expand Down

0 comments on commit e6af5a3

Please sign in to comment.