{"record":{"id":"9fde19ea4355a351","repo":"hatoo/oha","slug":"parse-header","errorCode":null,"errorMessage":"Parse header","messagePattern":"Parse header","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/cli.rs","lineNumber":6,"sourceCode":"use hyper::http::header::{HeaderName, HeaderValue};\nuse std::str::FromStr;\n\npub fn parse_header(s: &str) -> Result<(HeaderName, HeaderValue), anyhow::Error> {\n    let header = s.splitn(2, ':').collect::<Vec<_>>();\n    anyhow::ensure!(header.len() == 2, anyhow::anyhow!(\"Parse header\"));\n    let name = HeaderName::from_str(header[0])?;\n    let value = HeaderValue::from_str(header[1].trim_start_matches(' '))?;\n    Ok::<(HeaderName, HeaderValue), anyhow::Error>((name, value))\n}\n\npub fn parse_n_requests(s: &str) -> Result<usize, String> {\n    let s = s.trim().to_lowercase();\n    if let Some(num) = s.strip_suffix('k') {\n        num.parse::<f64>()\n            .map(|n| (n * 1000_f64) as usize)\n            .map_err(|e| e.to_string())\n    } else if let Some(num) = s.strip_suffix('m') {\n        num.parse::<f64>()\n            .map(|n| (n * 1_000_000_f64) as usize)\n            .map_err(|e| e.to_string())\n    } else {\n        s.parse::<usize>().map_err(|e| e.to_string())\n    }","sourceCodeStart":1,"sourceCodeEnd":24,"githubUrl":"https://github.com/hatoo/oha/blob/4efba2d113d165aaaf7533f5d2893e7cc57ebfc1/src/cli.rs#L1-L24","documentation":"parse_header converts a CLI header string like 'Name: value' into an http HeaderName/HeaderValue pair. It splits on the first ':' with splitn(2); if no colon is present the ensure fails with 'Parse header'. Invalid header names or values also fail, but at the subsequent from_str calls with different errors.","triggerScenarios":"Passing a -H/--header value without a colon, e.g. `-H Authorization` or `-H \"Bearer xyz\"`.","commonSituations":"Users separating the header name and value with a space instead of a colon; copying headers from a browser devtools 'name value' display; forgetting quotes so the shell splits the colon-containing string.","solutions":["Format each header as `Name: value`, e.g. `-H \"Authorization: Bearer xyz\"`.","Quote the argument so the shell preserves the colon-containing string.","Remember the value is trimmed of leading spaces, so extra spaces after the colon are fine."],"exampleFix":"// before\noha -H Authorization Bearer xyz https://example.com\n// after\noha -H \"Authorization: Bearer xyz\" https://example.com","handlingStrategy":"validation","validationCode":"fn valid_header_arg(s: &str) -> bool {\n    s.contains(':')\n}","typeGuard":"fn split_header(s: &str) -> Option<(&str, &str)> {\n    s.split_once(':')\n}","tryCatchPattern":"match parse_header(input) {\n    Ok((name, value)) => /* use header */,\n    Err(e) if e.to_string().contains(\"Parse header\") => {\n        eprintln!(\"Headers must be 'Name: value'; got: {input}\");\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Always quote -H values containing spaces or colons on the command line.","Use the 'Name: value' form copied from HTTP traces, not devtools name/value pairs.","Validate that each header string contains a colon before spawning oha."],"tags":["cli","http-headers","parsing"],"backgroundTag":"invalid-argument-format","analyzedSha":"4efba2d113d165aaaf7533f5d2893e7cc57ebfc1","analyzedAt":"2026-09-09T16:24:23.306Z","contentChangedAt":"2026-09-09T16:24:23.306Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}