{"record":{"id":"97a1c1314b6687ee","repo":"seanmonstar/warp","slug":"invalid-host-authority","errorCode":null,"errorMessage":"invalid host/authority","messagePattern":"invalid host/authority","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/filters/host.rs","lineNumber":24,"sourceCode":"pub use http::uri::Authority;\nuse std::str::FromStr;\n\n/// Creates a `Filter` that requires a specific authority (target server's\n/// host and port) in the request.\n///\n/// Authority is specified either in the `Host` header or in the target URI.\n///\n/// # Example\n///\n/// ```\n/// use warp::Filter;\n///\n/// let multihost =\n///     warp::host::exact(\"foo.com\").map(|| \"you've reached foo.com\")\n///     .or(warp::host::exact(\"bar.com\").map(|| \"you've reached bar.com\"));\n/// ```\npub fn exact(expected: &str) -> impl Filter<Extract = (), Error = Rejection> + Clone {\n    let expected = Authority::from_str(expected).expect(\"invalid host/authority\");\n    optional()\n        .and_then(move |option: Option<Authority>| match option {\n            Some(authority) if authority == expected => future::ok(()),\n            _ => future::err(reject::not_found()),\n        })\n        .untuple_one()\n}\n\n/// Creates a `Filter` that looks for an authority (target server's host\n/// and port) in the request.\n///\n/// Authority is specified either in the `Host` header or in the target URI.\n///\n/// If found, extracts the `Authority`, otherwise continues the request,\n/// extracting `None`.\n///\n/// Rejects with `400 Bad Request` if the `Host` header is malformed or if there\n/// is a mismatch between the `Host` header and the target URI.","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/seanmonstar/warp/blob/ff34d7213ed55ec342304aa7ff6ac4b351da9e66/src/filters/host.rs#L6-L42","documentation":"`warp::host::exact(expected)` parses its argument into an `Authority` and panics with \"invalid host/authority\" if parsing fails (src/filters/host.rs:24). Since routing on virtual hosts must compare against well-formed HTTP authorities, warp treats a malformed expected host as a programmer error at filter-construction time rather than a runtime rejection. The panic happens when you build the filter, not when a request arrives.","triggerScenarios":"Calling `warp::host::exact(\"foo .com\")`, `exact(\"\")`, `exact(\"host with space\")`, hosts with invalid characters (underscores in some positions, control chars), or values read from config/env that include a scheme or path like \"https://foo.com\".","commonSituations":"Feeding a full URL from config into `host::exact` instead of just the hostname; empty env vars (HOST=\"\") at deploy time; trailing slashes or ports out of range (port > 65535); uppercase/whitespace from copy-paste.","solutions":["Pass only the host (optionally with port): `warp::host::exact(\"foo.com\")` or `exact(\"foo.com:8080\")`","Strip scheme/path/whitespace from config values before building the filter","Trim and check the string is non-empty and parses via `http::uri::Authority::from_str` before calling `exact`","Normalize hostnames to lowercase, since Authority comparison is case-sensitive per byte"],"exampleFix":"// before\nlet filter = warp::host::exact(std::env::var(\"HOST\").unwrap());\n// after\nlet host = std::env::var(\"HOST\").unwrap().trim().to_string();\nassert!(!host.is_empty(), \"HOST must not be empty\");\nhttp::uri::Authority::from_str(&host).expect(\"HOST env var is not a valid authority\");\nlet filter = warp::host::exact(&host);","handlingStrategy":"validation","validationCode":"fn validate_authority(s: &str) -> Result<(), String> {\n    use std::str::FromStr;\n    if s.trim() != s || s.is_empty() {\n        return Err(\"host must be non-empty with no whitespace\".into());\n    }\n    http::uri::Authority::from_str(s).map(|_| ()).map_err(|e| format!(\"invalid authority '{}': {}\", s, e))\n}","typeGuard":"fn is_valid_authority(s: &str) -> bool {\n    use std::str::FromStr;\n    !s.trim().is_empty() && http::uri::Authority::from_str(s.trim()).is_ok()\n}","tryCatchPattern":null,"preventionTips":["Configure virtual hosts as bare hostnames (optionally :port), never full URLs","Trim and lowercase host values read from env/config before building filters","Fail fast at startup: parse every configured host before constructing filters","Remember Authority comparison is exact/case-sensitive — normalize consistently"],"tags":["panic","routing","http","configuration"],"backgroundTag":"invalid-argument-format","analyzedSha":"ff34d7213ed55ec342304aa7ff6ac4b351da9e66","analyzedAt":"2026-09-09T16:57:46.316Z","contentChangedAt":"2026-09-09T16:57:46.316Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}