{"record":{"id":"bfbf284e36107755","repo":"seanmonstar/warp","slug":"invalid-header-name","errorCode":null,"errorMessage":"invalid header name","messagePattern":"invalid header name","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/filters/reply.rs","lineNumber":189,"sourceCode":"{\n    type Wrapped = Map<F, WithDefaultHeader_>;\n\n    fn wrap(&self, filter: F) -> Self::Wrapped {\n        let with = WithDefaultHeader_ { with: self.clone() };\n        filter.map(with)\n    }\n}\n\nfn assert_name_and_value<K, V>(name: K, value: V) -> (HeaderName, HeaderValue)\nwhere\n    HeaderName: TryFrom<K>,\n    <HeaderName as TryFrom<K>>::Error: Into<http::Error>,\n    HeaderValue: TryFrom<V>,\n    <HeaderValue as TryFrom<V>>::Error: Into<http::Error>,\n{\n    let name = <HeaderName as TryFrom<K>>::try_from(name)\n        .map_err(Into::into)\n        .unwrap_or_else(|_| panic!(\"invalid header name\"));\n\n    let value = <HeaderValue as TryFrom<V>>::try_from(value)\n        .map_err(Into::into)\n        .unwrap_or_else(|_| panic!(\"invalid header value\"));\n\n    (name, value)\n}\n\nmod sealed {\n    use super::{WithDefaultHeader, WithHeader, WithHeaders};\n    use crate::generic::{Func, One};\n    use crate::reply::{Reply, Reply_};\n\n    #[derive(Clone)]\n    #[allow(missing_debug_implementations)]\n    pub struct WithHeader_ {\n        pub(super) with: WithHeader,\n    }","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/seanmonstar/warp/blob/ff34d7213ed55ec342304aa7ff6ac4b351da9e66/src/filters/reply.rs#L171-L207","documentation":"The reply::WithHeader/WithHeaders extension panics with 'invalid header name' when the header key passed to reply::with_header cannot be converted into an http::HeaderName via assert_name_and_value. Invalid keys (empty strings, non-token characters) are treated as programmer errors.","triggerScenarios":"reply::with_header(\"\", \"value\"), reply::with_header(\"bad header\", \"v\"), or any dynamic key failing HeaderName conversion when attaching headers to a reply.","commonSituations":"Injecting headers from request-derived or config-derived strings; typos like 'Content- Type'; constructing names by concatenation producing empty/invalid results.","solutions":["Use a valid header name literal or an http::header:: constant","Validate the dynamic key with HeaderName::try_from before calling with_header","Fix string-building logic that produces empty or malformed names"],"exampleFix":"// before\nreply::with_header(&format!(\"{}-{}\", prefix, suffix), \"v\")\n// after\nlet name = format!(\"{}-{}\", prefix, suffix);\nassert!(HeaderName::try_from(name.as_str()).is_ok(), \"invalid header name\");\nreply::with_header(name, \"v\")","handlingStrategy":"validation","validationCode":"if HeaderName::try_from(name.as_str()).is_err() { panic!(\"bad reply header name: {}\", name); }","typeGuard":"fn valid_reply_header_name(k: &str) -> Option<HeaderName> { HeaderName::try_from(k).ok() }","tryCatchPattern":null,"preventionTips":["Use http::header:: constants for static headers","Check dynamically-built names for emptiness/invalid chars","Unit-test reply construction with production header values"],"tags":["reply","headers","panic","invalid-argument"],"backgroundTag":"invalid-argument-value","analyzedSha":"ff34d7213ed55ec342304aa7ff6ac4b351da9e66","analyzedAt":"2026-09-09T16:57:46.316Z","contentChangedAt":"2026-09-09T16:57:46.316Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}