INNER CODE UNIT · Python

validation_exception_handler

slive777/OpenAver · web/app.py:316

async def validation_exception_handler(request: Request, exc: RequestValidationError):
    return JSONResponse(
        status_code=422,
        content={"error": "validation_error", "message": "請求格式錯誤,缺少必要欄位"}
    )


# ============ LAN 存取閘門 ============

# loopback 主機集合 —— 單一真理,middleware 短路與決策核心共用(避免兩處定義漂移)。
_LOOPBACK_HOSTS = frozenset({"127.0.0.1", "::1"})


def _lan_access_allowed(client_host, server_mode):
    """LAN access gate decision-core (testable, no I/O)。

    這是 middleware 實際委派的決策函式(非平行複製)——middleware 在非 loopback
    分支呼叫本函式,loopback 短路同樣比對 `_LOOPBACK_HOSTS`,故測得即所跑。

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…