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

chore: bump fastapi from 0.103.1 to 0.109.1 #72

Merged
merged 4 commits into from
Feb 13, 2024
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
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.

Loading