{"record":{"id":"d8af5ed2d4b361ca","repo":"caddyserver/caddy","slug":"header-d-invalid-format-s-expecting-fiel","errorCode":null,"errorMessage":"header %d: invalid format \\\"%s\\\" (expecting \\\"Field: value\\\")","messagePattern":"header (.+?): invalid format \\\\\"(.+?)\\\\\" \\(expecting \\\\\"Field: value\\\\\"\\)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/caddyhttp/staticresp.go","lineNumber":380,"sourceCode":"\t\t\tbodyBytes, err := io.ReadAll(os.Stdin)\n\t\t\tif err != nil {\n\t\t\t\treturn caddy.ExitCodeFailedStartup, err\n\t\t\t}\n\t\t\tbody = string(bodyBytes)\n\t\t}\n\t}\n\n\t// build headers map\n\theaders, err := fl.GetStringArray(\"header\")\n\tif err != nil {\n\t\treturn caddy.ExitCodeFailedStartup, fmt.Errorf(\"invalid header flag: %v\", err)\n\t}\n\thdr := make(http.Header)\n\tfor i, h := range headers {\n\t\tkey, val, found := strings.Cut(h, \":\")\n\t\tkey, val = strings.TrimSpace(key), strings.TrimSpace(val)\n\t\tif !found || key == \"\" || val == \"\" {\n\t\t\treturn caddy.ExitCodeFailedStartup, fmt.Errorf(\"header %d: invalid format \\\"%s\\\" (expecting \\\"Field: value\\\")\", i, h)\n\t\t}\n\t\thdr.Set(key, val)\n\t}\n\n\t// build each HTTP server\n\thttpApp := App{Servers: make(map[string]*Server)}\n\n\t// expand listen address, if more than one port\n\tlistenAddr, err := caddy.ParseNetworkAddress(listen)\n\tif err != nil {\n\t\treturn caddy.ExitCodeFailedStartup, err\n\t}\n\n\tif !listenAddr.IsUnixNetwork() && !listenAddr.IsFdNetwork() {\n\t\tlistenAddrs := make([]string, 0, listenAddr.PortRangeSize())\n\t\tfor offset := uint(0); offset < listenAddr.PortRangeSize(); offset++ {\n\t\t\tlistenAddrs = append(listenAddrs, listenAddr.JoinHostPort(offset))\n\t\t}","sourceCodeStart":362,"sourceCodeEnd":398,"githubUrl":"https://github.com/caddyserver/caddy/blob/50e54ee279aa1e504fe218ca49ab6ae16c100410/modules/caddyhttp/staticresp.go#L362-L398","documentation":"Thrown by Caddy's CLI 'respond' command (caddy respond --header flag) when a header argument cannot be split into a field and value. The code uses strings.Cut on ':' and requires both sides to be non-empty after trimming. It exists to reject malformed Header:Value pairs before the ad-hoc server starts.","triggerScenarios":"Running `caddy respond --header \"Foo\" ...` (no colon), `--header \"Foo: \"` or `--header \": bar\"` (empty key or value after TrimSpace). Only header strings where key or val is empty after trimming, or no ':' at all, fail; multiple 'a:b:c' is fine because Cut splits on the first colon.","commonSituations":"Shell quoting mistakes that swallow the colon, trailing whitespace-only values, copy-pasting header syntax from curl (-H \"Accept:\") which means 'remove header' and has no empty value here, or forgetting that the flag requires exactly 'Field: value'.","solutions":["Rewrite the flag value as 'Field: value', e.g. --header \"Content-Type: application/json\", with text on both sides of the colon","Check shell quoting: the whole 'Field: value' string must reach Caddy as one argument","Remove duplicate colons at the start or values that are only whitespace","If you intended an empty-valued header (rare), use a real Caddyfile with the header directive instead of caddy respond"],"exampleFix":"# before\ncaddy respond --listen :8080 --header \"X-Empty\" \"hi\"\n# or\ncaddy respond --header \"X-Val:\"\n\n# after\ncaddy respond --listen :8080 --header \"X-Empty: hi\"","handlingStrategy":"validation","validationCode":"# bash: validate each --header before invoking caddy\nfor h in \"Content-Type: application/json\" \"X-Empty\"; do\n  case \"$h\" in\n    *:*$'\\n'*) : ;;\n  esac\n  key=\"${h%%:*}\"; val=\"${h#*:}\"\n  key=\"${key// /}\"; [ -n \"$key\" ] || { echo \"bad header (empty key): $h\" >&2; exit 1; }\n  val=\"$(echo \"$val\" | sed 's/^ *//;s/ *$//')\"\n  [ -n \"$val\" ] || { echo \"bad header (empty value): $h\" >&2; exit 1; }\ndone","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Wrap caddy respond invocations in scripts with a header-format precheck loop","Quote each --header argument as a single shell word","Never pass curl-style 'Header:' (empty value) syntax to caddy respond"],"tags":["caddy","cli","headers","configuration"],"backgroundTag":null,"analyzedSha":"50e54ee279aa1e504fe218ca49ab6ae16c100410","analyzedAt":"2026-08-15T09:20:21.641Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}