From 2931041104d4936e1aa021726b35762412983954 Mon Sep 17 00:00:00 2001 From: Florian Sattler <65666934+florian-sattler@users.noreply.github.com> Date: Wed, 12 Mar 2025 05:23:10 +0100 Subject: [PATCH] relax HTTPBearer call requirement to support websockets --- fastapi/security/http.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fastapi/security/http.py b/fastapi/security/http.py index 9ab2df3c9..ae2be0244 100644 --- a/fastapi/security/http.py +++ b/fastapi/security/http.py @@ -8,7 +8,7 @@ from fastapi.openapi.models import HTTPBearer as HTTPBearerModel from fastapi.security.base import SecurityBase from fastapi.security.utils import get_authorization_scheme_param from pydantic import BaseModel -from starlette.requests import Request +from starlette.requests import Request, HTTPConnection from starlette.status import HTTP_401_UNAUTHORIZED, HTTP_403_FORBIDDEN from typing_extensions import Annotated, Doc @@ -299,7 +299,7 @@ class HTTPBearer(HTTPBase): self.auto_error = auto_error async def __call__( - self, request: Request + self, request: HTTPConnection ) -> Optional[HTTPAuthorizationCredentials]: authorization = request.headers.get("Authorization") scheme, credentials = get_authorization_scheme_param(authorization)