is_localhost_origin

Function is_localhost_origin 

Source
pub fn is_localhost_origin(origin: &HeaderValue) -> bool
Expand description

Checks if the given origin is a localhost origin.

§Valid Origins

  • http://localhost (any port)
  • http://127.0.0.1 (any port)
  • https://localhost (any port, for secure contexts)
  • https://127.0.0.1 (any port)

§Invalid Origins

  • External domains (e.g., http://example.com)
  • Other private IPs (e.g., http://192.168.1.1)
  • IPv6 localhost (currently not supported)

§Arguments

  • origin - The Origin header value to check

§Returns

true if the origin is a valid localhost origin, false otherwise.

§Example

use http::header::HeaderValue;
use reasonkit_web::cors::is_localhost_origin;

let origin = HeaderValue::from_static("http://localhost:3000");
assert!(is_localhost_origin(&origin));

let external = HeaderValue::from_static("http://example.com");
assert!(!is_localhost_origin(&external));