tsenart/vegeta · error

header '%s' has a wrong format

Error message

header '%s' has a wrong format

What it means

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.

Source

Thrown at flags.go:36

// headers is the http.Header used in each target request
// it is defined here to implement the flag.Value interface
// in order to support multiple identical flags for request header
// specification
type headers struct{ http.Header }

func (h headers) String() string {
	buf := &bytes.Buffer{}
	if err := h.Write(buf); err != nil {
		return ""
	}
	return buf.String()
}

// Set implements the flag.Value interface for a map of HTTP Headers.
func (h headers) Set(value string) error {
	parts := strings.SplitN(value, ":", 2)
	if len(parts) != 2 {
		return fmt.Errorf("header '%s' has a wrong format", value)
	}
	key, val := strings.TrimSpace(parts[0]), strings.TrimSpace(parts[1])
	if key == "" || val == "" {
		return fmt.Errorf("header '%s' has a wrong format", value)
	}
	// Add key/value directly to the http.Header (map[string][]string).
	// http.Header.Add() canonicalizes keys but vegeta is used
	// to test systems that require case-sensitive headers.
	h.Header[key] = append(h.Header[key], val)
	return nil
}

// localAddr implements the Flag interface for parsing net.IPAddr
type localAddr struct{ *net.IPAddr }

func (ip *localAddr) Set(value string) (err error) {
	ip.IPAddr, err = net.ResolveIPAddr("ip", value)
	return

View on GitHub (pinned to cf58112690)

Solutions

  1. Write headers as `-header="Key: Value"` with a colon separating a non-empty key and value.
  2. Quote the argument in the shell so spaces and colons survive (`-header="Authorization: Bearer abc"`).
  3. Validate each header string contains ':' with content on both sides before passing it to the flag.

Example fix

// before
vegeta attack -header=Authorization -targets=targets.txt
// after
vegeta attack -header="Authorization: Bearer <token>" -targets=targets.txt
Defensive patterns

Strategy: validation

Validate before calling

func validHeader(s string) bool {
    i := strings.Index(s, ":")
    if i <= 0 || i == len(s)-1 { return false }
    return strings.TrimSpace(s[:i]) != "" && strings.TrimSpace(s[i+1:]) != ""
}

Prevention

When it happens

Trigger: Passing `-header` a string without a colon (e.g. `-header=Authorization`), an empty key (`-header=': value'`), or an empty value (`-header='X-Token:'`).

Common situations: 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.

Related errors


AI-assisted analysis of tsenart/vegeta@cf58112690 (2026-08-31). Data as JSON: /api/errors/e27fb717fe92290f. Report an issue: GitHub.