valyala/fasthttp · error

fasthttp: unsupported http request method

Error message

fasthttp: unsupported http request method

What it means

fasthttp validates that the request method is one of the known HTTP methods (GET, POST, PUT, DELETE, HEAD, OPTIONS, CONNECT, TRACE, PATCH, etc.). ErrUnsupportedRequestMethod is returned when the method token does not match any recognized method, either during request parsing or when a method derived from a raw request line cannot be classified.

Source

Thrown at header.go:475

// 2. routing (e.g., Host),
// 3. request modifiers (e.g., controls and conditionals in Section 5 of [RFC7231]),
// 4. authentication (e.g., see [RFC7235] and [RFC6265]),
// 5. response control data (e.g., see Section 7.1 of [RFC7231]),
// 6. determining how to process the payload (e.g., Content-Encoding, Content-Type, Content-Range, and Trailer)
//
// Return ErrBadTrailer if contain any forbidden trailers.
func (h *header) AddTrailer(trailer string) error {
	return h.AddTrailerBytes(s2b(trailer))
}

var (
	ErrBadTrailer                    = errors.New("fasthttp: contain forbidden trailer")
	ErrReadingResponseHeaders        = errors.New("fasthttp: error when reading response headers")
	ErrReadingResponseTrailer        = errors.New("fasthttp: error when reading response trailer")
	ErrResponseFirstLineMissingSpace = errors.New("fasthttp: cannot find whitespace in the first line of response")
	ErrUnexpectedStatusCodeChar      = errors.New("fasthttp: unexpected char at the end of status code")
	ErrMissingRequestMethod          = errors.New("fasthttp: cannot find http request method")
	ErrUnsupportedRequestMethod      = errors.New("fasthttp: unsupported http request method")
	ErrExtraWhitespaceInRequestLine  = errors.New("fasthttp: extra whitespace in request line")
	ErrEmptyRequestURI               = errors.New("fasthttp: requesturi cannot be empty")
	ErrDuplicateContentLength        = errors.New("fasthttp: duplicate content-length header")
	ErrUnsupportedTransferEncoding   = errors.New("fasthttp: unsupported transfer-encoding")
	ErrNonNumericChars               = errors.New("fasthttp: non-numeric chars found")
	ErrNeedMore                      = errors.New("fasthttp: need more data: cannot find trailing lf")
	ErrSmallReadBuffer               = errors.New("fasthttp: small read buffer. increase readbuffersize")
)

// AddTrailerBytes add Trailer header value for chunked response
// to indicate which headers will be sent after the body.
//
// Use Set to set the trailer header later.
//
// Trailers are only supported with chunked transfer.
// Trailers allow the sender to include additional headers at the end of chunked messages.
//
// The following trailers are forbidden:

View on GitHub (pinned to c96f600972)

Solutions

  1. Use one of the standard fasthttp.Method* constants for the method.
  2. If you need a nonstandard verb, upgrade fasthttp — newer versions recognize more methods — or bypass validation by writing the raw request bytes yourself.
  3. For WebDAV/CalDAV verbs (PROPFIND, REPORT...), check your fasthttp version supports them; if not, send via net/http or raw connection.
  4. Fix typos: methods are case-sensitive uppercase tokens.

Example fix

// before
req.Header.SetMethod("getall") // unsupported
c.Do(&req, &resp)
// after
req.Header.SetMethod(fasthttp.MethodGet)
c.Do(&req, &resp)
Defensive patterns

Strategy: validation

Validate before calling

m := req.Header.Method
if len(m) == 0 || !isKnownHTTPMethod(m) {
    return fmt.Errorf("unsupported method %q", m)
}
// isKnownHTTPMethod checks against fasthttp's method token table

Type guard

func isKnownHTTPMethod(m []byte) bool {
    switch string(m) {
    case "GET", "HEAD", "POST", "PUT", "DELETE", "CONNECT", "OPTIONS", "TRACE", "PATCH":
        return true
    }
    return false
}

Try / catch

if err := client.Do(req, resp); err == fasthttp.ErrUnsupportedRequestMethod {
    return fmt.Errorf("method %q not accepted: %w", req.Header.Method, err)
}

Prevention

When it happens

Trigger: Parsing a request whose first token is not a valid method (e.g. garbage input, custom verbs sent to a parser that rejects them), or server/client code paths that validate h.Method against the known-method set; requesting with Method set to a typo like "Getall".

Common situations: Custom RPC-over-HTTP verbs (e.g. 'SUBSCRIBE', 'REPORT' for CalDAV/WebDAV) used with an older fasthttp version whose method table lacks them; typos in SetMethod; fuzzed or hostile traffic to a fasthttp server.

Related errors


AI-assisted analysis of valyala/fasthttp@c96f600972 (2026-08-31). Data as JSON: /api/errors/44b35341d8bc2421. Report an issue: GitHub.