INNER CODE UNIT · Python

static_response

ImFeH2/huddol · core/src/fora/adapters/websocket/server.py:297

def static_response(directory: Path, path: str) -> web.Response:
    if not directory.is_dir():
        return web.Response(status=503, text="Frontend not built")
    relative = unquote(path).lstrip("/")
    target = directory / "index.html"
    if "." in relative:
        target = (directory / relative).resolve()
        if not target.is_relative_to(directory.resolve()) or not target.is_file():
            return web.Response(status=404, text="Not found")
    if not target.is_file():
        return web.Response(status=503, text="Frontend not built")
    content_type = CONTENT_TYPES.get(target.suffix.lower(), "application/octet-stream")
    return web.Response(
        headers={"Content-Type": content_type}, body=target.read_bytes()
    )


class WebServer:

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…