Skip to content

Commit

Permalink
chore: bump fastapi from 0.103.1 to 0.109.1 (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
dependabot[bot] authored Feb 13, 2024
1 parent dc3c742 commit 748d473
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
13 changes: 8 additions & 5 deletions aidial_sdk/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,11 @@ async def _healthcheck() -> JSONResponse:
return JSONResponse(content={"status": "ok"})

@staticmethod
def _exception_handler(request: Request, exc: HTTPException):
return JSONResponse(
status_code=exc.status_code,
content=exc.detail,
)
def _exception_handler(request: Request, exc: Exception):
if isinstance(exc, HTTPException):
return JSONResponse(
status_code=exc.status_code,
content=exc.detail,
)
else:
raise exc
13 changes: 6 additions & 7 deletions aidial_sdk/header_propagator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,21 @@
from fastapi import FastAPI
from requests import PreparedRequest
from requests.sessions import Session
from starlette.middleware.exceptions import ExceptionMiddleware
from starlette.types import ASGIApp, Receive, Scope, Send


class FastAPIMiddleware:
def __init__(
self,
app: ExceptionMiddleware,
app: ASGIApp,
api_key: ContextVar[Optional[str]],
) -> None:
self.app = app
self.api_key = api_key

async def __call__(self, scope, receive, send) -> None:
async def __call__(
self, scope: Scope, receive: Receive, send: Send
) -> None:
for header in scope["headers"]:
if header[0] == b"api-key":
self.api_key.set(header[1].decode("utf-8"))
Expand Down Expand Up @@ -54,10 +56,7 @@ def enable(self):
self._enabled = True

def _instrument_fast_api(self, app: FastAPI):
app.add_middleware(
FastAPIMiddleware,
api_key=self._api_key,
)
app.add_middleware(FastAPIMiddleware, self._api_key)

def _instrument_aiohttp(self):
def instrumented_init(wrapped, instance, args, kwargs):
Expand Down
23 changes: 11 additions & 12 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 748d473

Please sign in to comment.