Fix login cookie not being set correctly. Closes #310

This commit is contained in:
arabcoders 2025-06-24 16:08:55 +03:00
parent 43aef86e7e
commit a9cb816050

View file

@ -153,7 +153,6 @@ class HttpAPI:
Args: Args:
username (str): The username. username (str): The username.
password (str): The password. password (str): The password.
this (HttpAPI): The instance of the HttpAPI.
Returns: Returns:
Awaitable: The middleware handler. Awaitable: The middleware handler.
@ -213,9 +212,10 @@ class HttpAPI:
}, },
) )
response = await handler(request) response: Response = await handler(request)
if request.path != "/": contentType: str | None = response.headers.get("content-type", None)
if contentType and not contentType.startswith("text/html"):
return response return response
try: try:
@ -226,7 +226,7 @@ class HttpAPI:
key=Config.get_instance().secret_key, key=Config.get_instance().secret_key,
), ),
max_age=60 * 60 * 24 * 7, max_age=60 * 60 * 24 * 7,
expires=datetime.now(UTC) + timedelta(days=7), expires=(datetime.now(UTC) + timedelta(days=7)).strftime("%a, %d %b %Y %H:%M:%S GMT"),
httponly=True, httponly=True,
samesite="Strict", samesite="Strict",
) )
@ -259,7 +259,7 @@ class HttpAPI:
}, },
) )
response = await handler(request) response: Response = await handler(request)
contentType: str | None = response.headers.get("content-type", None) contentType: str | None = response.headers.get("content-type", None)
if contentType and "/" != base_path and contentType.startswith("text/html"): if contentType and "/" != base_path and contentType.startswith("text/html"):
@ -272,11 +272,8 @@ class HttpAPI:
.replace('baseURL:""', f'baseURL:"{rewrite_path}/"') .replace('baseURL:""', f'baseURL:"{rewrite_path}/"')
) )
return web.Response( response.body = content.encode("utf-8")
body=content.encode("utf-8"), return response
status=response.status,
headers=response.headers,
)
if request.path.startswith(static_path) and isinstance(response, web.FileResponse): if request.path.startswith(static_path) and isinstance(response, web.FileResponse):
try: try: