pub async fn same_subnet(
__arg0: State<LocalSubnets>,
request: Request,
next: Next,
) -> ResponseAvailable on crate feature
connect-server only.Expand description
Refuse a request that did not come from this host’s subnet.
Wrap the LAN-only routes in this, as axum::middleware::from_fn_with_state. The
router does not do it for you because it cannot know whether the host is a LAN endpoint
at all — a WAN endpoint “cannot implement these operations” and should return 404
instead.
Requires the server to have been started with
into_make_service_with_connect_info::<SocketAddr>(), or there is no peer address to
check and every request is refused.
use s2_kit::connect::server::{LocalSubnets, same_subnet};
let subnets = LocalSubnets::detect()?;
let guarded = lan_only.layer(axum::middleware::from_fn_with_state(
subnets,
same_subnet,
));