Skip to content

Commit e6af5a3

Browse files
committed
chore: reorg code
1 parent cd64125 commit e6af5a3

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

src/stac_auth_proxy/app.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ def create_app(settings: Optional[Settings] = None) -> FastAPI:
2222
"""FastAPI Application Factory."""
2323
settings = settings or Settings()
2424

25-
app = FastAPI(openapi_url=None)
25+
app = FastAPI(
26+
openapi_url=None,
27+
)
2628
app.add_middleware(AddProcessTimeHeaderMiddleware)
2729

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

38+
if settings.debug:
39+
app.add_api_route(
40+
"/_debug",
41+
lambda: {"settings": settings},
42+
methods=["GET"],
43+
)
44+
3645
proxy_handler = ReverseProxyHandler(upstream=str(settings.upstream_url))
3746
openapi_handler = OpenApiSpecHandler(
3847
proxy=proxy_handler, oidc_config_url=str(settings.oidc_discovery_url)
@@ -63,13 +72,6 @@ def create_app(settings: Optional[Settings] = None) -> FastAPI:
6372
methods=methods,
6473
)
6574

66-
if settings.debug:
67-
app.add_api_route(
68-
"/_debug",
69-
lambda: {"settings": settings},
70-
methods=["GET"],
71-
)
72-
7375
# Catchall for remainder of the endpoints
7476
app.add_api_route(
7577
"/{path:path}",

src/stac_auth_proxy/handlers/reverse_proxy.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,13 @@ async def proxy_request(self, request: Request, *, stream=False) -> httpx.Respon
3434
headers.setdefault("X-Forwarded-Host", request.url.hostname)
3535

3636
# https://github.com/fastapi/fastapi/discussions/7382#discussioncomment-5136466
37+
url = httpx.URL(
38+
path=request.url.path,
39+
query=request.url.query.encode("utf-8"),
40+
)
3741
rp_req = self.client.build_request(
3842
request.method,
39-
url=httpx.URL(
40-
path=request.url.path,
41-
query=request.url.query.encode("utf-8"),
42-
),
43+
url=url,
4344
headers=headers,
4445
content=request.stream(),
4546
)

0 commit comments

Comments
 (0)