{"record":{"id":"321e7763e9bd9fb6","repo":"seanmonstar/warp","slug":"invalid-header-value","errorCode":null,"errorMessage":"invalid header value","messagePattern":"invalid header value","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/filters/reply.rs","lineNumber":193,"sourceCode":"        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    }\n\n    impl<R: Reply> Func<One<R>> for WithHeader_ {\n        type Output = Reply_;\n","sourceCodeStart":175,"sourceCodeEnd":211,"githubUrl":"https://github.com/seanmonstar/warp/blob/ff34d7213ed55ec342304aa7ff6ac4b351da9e66/src/filters/reply.rs#L175-L211","documentation":"assert_name_and_value in reply.rs panics with 'invalid header value' when the value passed to reply::with_header/default_header cannot be converted into an http::HeaderValue. HeaderValues must be visible ASCII (or obs-text); bytes with control characters, newlines, or invalid UTF-8 fail conversion.","triggerScenarios":"reply::with_header(\"x-id\", \"line1\\nline2\"), passing raw binary/UTF-8 multibyte data, or values containing NUL bytes.","commonSituations":"Echoing user input or file contents into response headers; header-injection sanitization failures; logging payloads into headers.","solutions":["Sanitize the value: strip \\r, \\n and non-visible-ASCII bytes before use","Use HeaderValue::from_bytes/mime-percent-encode and only pass if conversion succeeds","Move large/binary data into the response body instead of headers"],"exampleFix":"// before\nreply::with_header(\"x-note\", &user_input)\n// after\nlet v = user_input.chars().filter(|c| !c.is_control()).collect::<String>();\nreply::with_header(\"x-note\", v)","handlingStrategy":"validation","validationCode":"fn valid_header_value(v: &str) -> bool { HeaderValue::try_from(v).is_ok() }\nassert!(valid_header_value(value));","typeGuard":"fn sanitized_header_value(v: &str) -> Option<HeaderValue> { HeaderValue::try_from(v.chars().filter(|c| !c.is_control()).collect::<String>()).ok() }","tryCatchPattern":null,"preventionTips":["Strip control characters (\\r, \\n, NUL) from values destined for headers","Never echo raw user/binary input into headers","Use HeaderValue::from_bytes as a pre-check"],"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-16T04:17:20.429Z"}