HTTPBase Class — fastapi Architecture
Architecture documentation for the HTTPBase class in http.py from the fastapi codebase.
Entity Profile
Dependency Diagram
graph TD 3095b424_1269_68c9_350e_1ccbc9dc52df["HTTPBase"] 28c8873a_5ba4_867f_0824_7abcac157a85["SecurityBase"] 3095b424_1269_68c9_350e_1ccbc9dc52df -->|extends| 28c8873a_5ba4_867f_0824_7abcac157a85 96278b4c_a391_681f_b974_563be8af72ce["http.py"] 3095b424_1269_68c9_350e_1ccbc9dc52df -->|defined in| 96278b4c_a391_681f_b974_563be8af72ce c1ab28c1_2a87_d875_3fd3_d74775dd04cb["__init__()"] 3095b424_1269_68c9_350e_1ccbc9dc52df -->|method| c1ab28c1_2a87_d875_3fd3_d74775dd04cb 974dca00_b535_c294_ff38_23cb4d603d3a["make_authenticate_headers()"] 3095b424_1269_68c9_350e_1ccbc9dc52df -->|method| 974dca00_b535_c294_ff38_23cb4d603d3a 8a4f3cb1_2bb3_9484_ab7e_5424511db588["make_not_authenticated_error()"] 3095b424_1269_68c9_350e_1ccbc9dc52df -->|method| 8a4f3cb1_2bb3_9484_ab7e_5424511db588 cb3daacf_079f_f435_38c5_84f493cf166b["__call__()"] 3095b424_1269_68c9_350e_1ccbc9dc52df -->|method| cb3daacf_079f_f435_38c5_84f493cf166b
Relationship Graph
Source Code
fastapi/security/http.py lines 69–104
class HTTPBase(SecurityBase):
def __init__(
self,
*,
scheme: str,
scheme_name: Optional[str] = None,
description: Optional[str] = None,
auto_error: bool = True,
):
self.model: HTTPBaseModel = HTTPBaseModel(
scheme=scheme, description=description
)
self.scheme_name = scheme_name or self.__class__.__name__
self.auto_error = auto_error
def make_authenticate_headers(self) -> dict[str, str]:
return {"WWW-Authenticate": f"{self.model.scheme.title()}"}
def make_not_authenticated_error(self) -> HTTPException:
return HTTPException(
status_code=HTTP_401_UNAUTHORIZED,
detail="Not authenticated",
headers=self.make_authenticate_headers(),
)
async def __call__(
self, request: Request
) -> Optional[HTTPAuthorizationCredentials]:
authorization = request.headers.get("Authorization")
scheme, credentials = get_authorization_scheme_param(authorization)
if not (authorization and scheme and credentials):
if self.auto_error:
raise self.make_not_authenticated_error()
else:
return None
return HTTPAuthorizationCredentials(scheme=scheme, credentials=credentials)
Domain
Defined In
Extends
Source
Frequently Asked Questions
What is the HTTPBase class?
HTTPBase is a class in the fastapi codebase, defined in fastapi/security/http.py.
Where is HTTPBase defined?
HTTPBase is defined in fastapi/security/http.py at line 69.
What does HTTPBase extend?
HTTPBase extends SecurityBase.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free