vitessio/vitess · warning

Method not allowed

Error message

Method not allowed

What it means

The tabletserver /debugenv endpoint only accepts POST (set a variable) and GET (read variables); any other HTTP method gets a 405 'Method not allowed'. This is method-based routing in debugEnvHandler's switch on r.Method.

Source

Thrown at go/vt/vttablet/tabletserver/debugenv.go:80

	return append(vars, envValue{
		Name:  name,
		Value: fmt.Sprintf("%v", f()),
	})
}

func debugEnvHandler(tsv *TabletServer, w http.ResponseWriter, r *http.Request) {
	if err := acl.CheckAccessHTTP(r, acl.ADMIN); err != nil {
		acl.SendError(w, err)
		return
	}

	switch r.Method {
	case http.MethodPost:
		handlePost(tsv, w, r)
	case http.MethodGet:
		handleGet(tsv, w, r)
	default:
		http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
	}
}

func handlePost(tsv *TabletServer, w http.ResponseWriter, r *http.Request) {
	varname := r.FormValue("varname")
	value := r.FormValue("value")

	var msg string
	if varname == "" || value == "" {
		http.Error(w, "Missing varname or value", http.StatusBadRequest)
		return
	}

	setIntVal := func(f func(int)) error {
		ival, err := strconv.Atoi(value)
		if err != nil {
			return fmt.Errorf("invalid int value for %v: %v", varname, err)
		}

View on GitHub (pinned to 01a25a7d17)

Solutions

  1. Use POST to set a variable (varname/value form fields) or GET to list them
  2. Fix the client/proxy to send GET or POST only
  3. If a middleware rewrites methods, whitelist /debugenv from such rewrites

Example fix

// before
curl -X PUT 'http://tablet:15100/debugenv?varname=x&value=1'
// after
curl -X POST 'http://tablet:15100/debugenv' -d 'varname=x&value=1'
Defensive patterns

Strategy: validation

Validate before calling

if method != http.MethodGet && method != http.MethodPost {
    return fmt.Errorf("/debugenv only supports GET and POST, got %s", method)
}

Prevention

When it happens

Trigger: Sending PUT, DELETE, HEAD, etc. to /debugenv on a vttablet's debug port.

Common situations: REST clients or proxies assuming full CRUD on debug endpoints; misconfigured health checkers using HEAD/DELETE; copy-pasted client code hitting the wrong verb.

Related errors


AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01). Data as JSON: /api/errors/98f42f583d14ce65. Report an issue: GitHub.