Add redirect

This commit is contained in:
0880
2026-01-20 19:15:57 +03:30
parent bd4a4bd6ac
commit 5eaa5527b6
2 changed files with 17 additions and 1 deletions

View File

@@ -298,6 +298,12 @@ def render(request: Request, file: str | Path, variables: dict[str, Any] = {}) -
return HTTPResponse(request, content, content_type="text/html; charset=utf-8")
def redirect(location: str):
return f"HTTP/1.1 301 Temporary Redirect\r\nContent-Length: 0\r\nLocation: {location}".encode(
encoding="utf-8"
)
def JSONResponse(request: Request, d: dict, status=200) -> bytes:
return HTTPResponse(
request, json.dumps(d), status=status, content_type="text/json; charset=utf-8"