|
|
@ -1,10 +1,6 @@ |
|
|
from collections.abc import Awaitable, Callable, Coroutine, Sequence |
|
|
from collections.abc import Awaitable, Callable, Coroutine, Sequence |
|
|
from enum import Enum |
|
|
from enum import Enum |
|
|
from typing import ( |
|
|
from typing import Annotated, Any, TypeVar, cast |
|
|
Annotated, |
|
|
|
|
|
Any, |
|
|
|
|
|
TypeVar, |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
from annotated_doc import Doc |
|
|
from annotated_doc import Doc |
|
|
from fastapi import routing |
|
|
from fastapi import routing |
|
|
@ -1033,11 +1029,11 @@ class FastAPI(Starlette): |
|
|
exception_handlers[key] = value |
|
|
exception_handlers[key] = value |
|
|
|
|
|
|
|
|
middleware = ( |
|
|
middleware = ( |
|
|
[Middleware(ServerErrorMiddleware, handler=error_handler, debug=debug)] |
|
|
[Middleware(ServerErrorMiddleware, handler=error_handler, debug=debug)] # type: ignore[invalid-argument-type] |
|
|
+ self.user_middleware |
|
|
+ self.user_middleware |
|
|
+ [ |
|
|
+ [ |
|
|
Middleware( |
|
|
Middleware( |
|
|
ExceptionMiddleware, handlers=exception_handlers, debug=debug |
|
|
ExceptionMiddleware, handlers=exception_handlers, debug=debug # type: ignore[invalid-argument-type] |
|
|
), |
|
|
), |
|
|
# Add FastAPI-specific AsyncExitStackMiddleware for closing files. |
|
|
# Add FastAPI-specific AsyncExitStackMiddleware for closing files. |
|
|
# Before this was also used for closing dependencies with yield but |
|
|
# Before this was also used for closing dependencies with yield but |
|
|
@ -1058,7 +1054,7 @@ class FastAPI(Starlette): |
|
|
# user middlewares, the same context is used. |
|
|
# user middlewares, the same context is used. |
|
|
# This is currently not needed, only for closing files, but used to be |
|
|
# This is currently not needed, only for closing files, but used to be |
|
|
# important when dependencies with yield were closed here. |
|
|
# important when dependencies with yield were closed here. |
|
|
Middleware(AsyncExitStackMiddleware), |
|
|
Middleware(AsyncExitStackMiddleware), # type: ignore[invalid-argument-type] |
|
|
] |
|
|
] |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
@ -4640,7 +4636,7 @@ class FastAPI(Starlette): |
|
|
""" |
|
|
""" |
|
|
|
|
|
|
|
|
def decorator(func: DecoratedCallable) -> DecoratedCallable: |
|
|
def decorator(func: DecoratedCallable) -> DecoratedCallable: |
|
|
self.add_middleware(BaseHTTPMiddleware, dispatch=func) |
|
|
self.add_middleware(BaseHTTPMiddleware, dispatch=func) # type: ignore[arg-type] |
|
|
return func |
|
|
return func |
|
|
|
|
|
|
|
|
return decorator |
|
|
return decorator |
|
|
|