mirror of https://github.com/tiangolo/fastapi.git
♻ Instantiate `HTTPException` only when needed, optimization refactor (#5356)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
This commit is contained in:
parent
4b31beef35
commit
010d44ee1b
|
|
@ -73,11 +73,6 @@ class HTTPBasic(HTTPBase):
|
||||||
unauthorized_headers = {"WWW-Authenticate": f'Basic realm="{self.realm}"'}
|
unauthorized_headers = {"WWW-Authenticate": f'Basic realm="{self.realm}"'}
|
||||||
else:
|
else:
|
||||||
unauthorized_headers = {"WWW-Authenticate": "Basic"}
|
unauthorized_headers = {"WWW-Authenticate": "Basic"}
|
||||||
invalid_user_credentials_exc = HTTPException(
|
|
||||||
status_code=HTTP_401_UNAUTHORIZED,
|
|
||||||
detail="Invalid authentication credentials",
|
|
||||||
headers=unauthorized_headers,
|
|
||||||
)
|
|
||||||
if not authorization or scheme.lower() != "basic":
|
if not authorization or scheme.lower() != "basic":
|
||||||
if self.auto_error:
|
if self.auto_error:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
|
@ -87,6 +82,11 @@ class HTTPBasic(HTTPBase):
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
invalid_user_credentials_exc = HTTPException(
|
||||||
|
status_code=HTTP_401_UNAUTHORIZED,
|
||||||
|
detail="Invalid authentication credentials",
|
||||||
|
headers=unauthorized_headers,
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
data = b64decode(param).decode("ascii")
|
data = b64decode(param).decode("ascii")
|
||||||
except (ValueError, UnicodeDecodeError, binascii.Error):
|
except (ValueError, UnicodeDecodeError, binascii.Error):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue