Skip to content

shared

is_localhost

Python
is_localhost(request: Request) -> bool

Whether the request's direct TCP peer is the loopback interface, regardless of which interface the server itself is bound to. Shared by every router that gates a write behind "only from the machine running Dojo" (settings, and the What's Changed toggle).

Source code in src/mujoco_mojo/utils/layers/dojo/shared.py
Python
def is_localhost(request: Request) -> bool:
    """Whether the request's direct TCP peer is the loopback interface, regardless of which interface the server itself is bound to. Shared by every router that gates a write behind "only from the machine running Dojo" (settings, and the What's Changed toggle)."""
    host = request.client.host if request.client else None
    if host is None:
        return False
    try:
        return ipaddress.ip_address(host).is_loopback
    except ValueError:
        return False