tsenart/vegeta · error

bad method: %s

Error message

bad method: %s

What it means

Returned when a target line starts with a token that is not a recognized HTTP method. The line parsed into METHOD URL but startsWithHTTPMethod rejects the first token, so vegeta wraps it as "bad method".

Source

Thrown at lib/targets.go:296

			line = strings.TrimSpace(sc.Text())

			if len(line) != 0 && line[0] != '#' {
				break
			}
		}

		tgt.Body = body
		tgt.Header = http.Header{}
		for k, vs := range hdr {
			tgt.Header[k] = vs
		}

		tokens := strings.SplitN(line, " ", 2)
		if len(tokens) < 2 {
			return fmt.Errorf("bad target: %s", line)
		}
		if !startsWithHTTPMethod(line) {
			return fmt.Errorf("bad method: %s", tokens[0])
		}
		tgt.Method = tokens[0]
		if _, err = url.ParseRequestURI(tokens[1]); err != nil {
			return fmt.Errorf("bad URL: %s, %w", tokens[1], err)
		}
		tgt.URL = tokens[1]
		line = strings.TrimSpace(sc.Peek())
		if line == "" || startsWithHTTPMethod(line) {
			return nil
		}
		for sc.Scan() {
			if line = strings.TrimSpace(sc.Text()); line == "" {
				break
			} else if strings.HasPrefix(line, "#") {
				continue
			} else if strings.HasPrefix(line, "@") {
				if tgt.Body, err = os.ReadFile(line[1:]); err != nil {
					return fmt.Errorf("bad body: %w", err)

View on GitHub (pinned to cf58112690)

Solutions

  1. Use a standard uppercase HTTP method as the first token: GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS.
  2. Fix typos in the method name on the offending line.
  3. Replace placeholder variables with a real method before passing the targets file to vegeta.
  4. If you need a custom method, check startsWithHTTPMethod's supported list and upgrade vegeta or preprocess the file.

Example fix

// before
curl http://localhost:8080/
// after
GET http://localhost:8080/
Defensive patterns

Strategy: validation

Validate before calling

var httpMethods = []string{"GET","HEAD","POST","PUT","PATCH","DELETE","CONNECT","OPTIONS","TRACE"}
func hasHTTPMethod(line string) bool {
    m := strings.ToUpper(strings.Fields(line)[0])
    return slices.Contains(httpMethods, m)
}

Try / catch

if _, err := vegeta.NewTargets(r); err != nil {
    var bad *fmt.wrapError
    if strings.Contains(err.Error(), "bad method:") {
        return fmt.Errorf("use a standard uppercase HTTP method: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: A targets line whose first token is not one of GET/POST/PUT/DELETE/PATCH/HEAD/OPTIONS etc., e.g. "get" capitalized differently if unsupported, or a typo like "GETT http://..." or "get-http://x".

Common situations: Typos in targets files, custom/unsupported verbs (e.g. PROPFIND if not in the recognized list), template placeholders left unfilled like "{{METHOD}} http://...".

Related errors


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