Skip to main content

github_mcp/http/
localhost_detector.rs

1// GitHub v3 REST API MCP server — generated by mcpify. Do not hand-edit.
2
3use std::net::IpAddr;
4
5/// Requests from localhost get relaxed auth requirements — the same
6/// localhost-vs-network binding distinction proven useful in the reference
7/// servers (looser auth only when bound to localhost, never over an exposed
8/// network interface).
9pub fn is_localhost(addr: IpAddr) -> bool {
10    addr.is_loopback()
11}
12
13#[cfg(test)]
14mod tests {
15    use super::*;
16
17    #[test]
18    fn recognizes_loopback_addresses() {
19        assert!(is_localhost("127.0.0.1".parse().unwrap()));
20        assert!(is_localhost("::1".parse().unwrap()));
21    }
22
23    #[test]
24    fn rejects_non_loopback_addresses() {
25        assert!(!is_localhost("10.0.0.5".parse().unwrap()));
26    }
27}