{"record":{"id":"e27fb717fe92290f","repo":"tsenart/vegeta","slug":"header-s-has-a-wrong-format","errorCode":null,"errorMessage":"header '%s' has a wrong format","messagePattern":"header '(.+?)' has a wrong format","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"flags.go","lineNumber":36,"sourceCode":"// headers is the http.Header used in each target request\n// it is defined here to implement the flag.Value interface\n// in order to support multiple identical flags for request header\n// specification\ntype headers struct{ http.Header }\n\nfunc (h headers) String() string {\n\tbuf := &bytes.Buffer{}\n\tif err := h.Write(buf); err != nil {\n\t\treturn \"\"\n\t}\n\treturn buf.String()\n}\n\n// Set implements the flag.Value interface for a map of HTTP Headers.\nfunc (h headers) Set(value string) error {\n\tparts := strings.SplitN(value, \":\", 2)\n\tif len(parts) != 2 {\n\t\treturn fmt.Errorf(\"header '%s' has a wrong format\", value)\n\t}\n\tkey, val := strings.TrimSpace(parts[0]), strings.TrimSpace(parts[1])\n\tif key == \"\" || val == \"\" {\n\t\treturn fmt.Errorf(\"header '%s' has a wrong format\", value)\n\t}\n\t// Add key/value directly to the http.Header (map[string][]string).\n\t// http.Header.Add() canonicalizes keys but vegeta is used\n\t// to test systems that require case-sensitive headers.\n\th.Header[key] = append(h.Header[key], val)\n\treturn nil\n}\n\n// localAddr implements the Flag interface for parsing net.IPAddr\ntype localAddr struct{ *net.IPAddr }\n\nfunc (ip *localAddr) Set(value string) (err error) {\n\tip.IPAddr, err = net.ResolveIPAddr(\"ip\", value)\n\treturn","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/tsenart/vegeta/blob/cf5811269046c672a604b1eb352204d30f16ae4a/flags.go#L18-L54","documentation":"The headers flag implements flag.Value; Set() requires each header to be a `Key: Value` pair split on the first colon, with non-empty key and value after trimming spaces. Anything else — no colon, empty key, or empty value — returns this error.","triggerScenarios":"Passing `-header` a string without a colon (e.g. `-header=Authorization`), an empty key (`-header=': value'`), or an empty value (`-header='X-Token:'`).","commonSituations":"Users forgetting the colon between header name and value; shell quoting stripping the intended value; programmatic callers building header strings by concatenation and omitting the value; headers defined in config files where 'Key:' has no value part.","solutions":["Write headers as `-header=\"Key: Value\"` with a colon separating a non-empty key and value.","Quote the argument in the shell so spaces and colons survive (`-header=\"Authorization: Bearer abc\"`).","Validate each header string contains ':' with content on both sides before passing it to the flag."],"exampleFix":"// before\nvegeta attack -header=Authorization -targets=targets.txt\n// after\nvegeta attack -header=\"Authorization: Bearer <token>\" -targets=targets.txt","handlingStrategy":"validation","validationCode":"func validHeader(s string) bool {\n    i := strings.Index(s, \":\")\n    if i <= 0 || i == len(s)-1 { return false }\n    return strings.TrimSpace(s[:i]) != \"\" && strings.TrimSpace(s[i+1:]) != \"\"\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always format -header as \"Key: Value\" with both parts non-empty.","Quote header arguments in shell to preserve colons and spaces.","Validate headers from config files before injecting them into the CLI."],"tags":["cli","flags","validation","http-headers"],"backgroundTag":"invalid-flag-format","analyzedSha":"cf5811269046c672a604b1eb352204d30f16ae4a","analyzedAt":"2026-08-31T11:04:20.464Z","schemaVersion":2},"datasetVersion":"2026-09-01T08:17:40.651Z"}