Skip to main content

host_with

Function host_with 

Source
pub fn host_with(
    req: &HttpRequest,
    public_origin: Option<&str>,
    trust_proxy: bool,
) -> String
Expand description

The authority a request should be treated as addressed to, with the configuration passed explicitly.

Order: the configured public origin; with trust_proxy, X-Forwarded-Host then Forwarded; the plain Host header; the request URI authority; the server’s own bound address. Without trust_proxy the forwarding headers are never read, so a client cannot retarget NIP-98 URL matching or generated links by sending them.

use actix_web::test::TestRequest;
use solid_pod_rs_server::scheme::host_with;

let req = TestRequest::get()
    .insert_header(("host", "pod.example"))
    .insert_header(("x-forwarded-host", "evil.example"))
    .to_http_request();
assert_eq!(host_with(&req, None, false), "pod.example");
assert_eq!(host_with(&req, None, true), "evil.example");
assert_eq!(host_with(&req, Some("https://pod.example"), true), "pod.example");