valyala/fasthttp · error

fasthttp: non-get request received

Error message

fasthttp: non-get request received

What it means

When fasthttp.Server is configured with GetOnly=true, it accepts only GET (and HEAD) requests; any other method causes ReadRequest to fail with ErrGetOnly. This is a deliberate server-side restriction, not a bug.

Source

Thrown at http.go:1369

//
// If MayContinue returns true, the caller must:
//
//   - Either send StatusExpectationFailed response if request headers don't
//     satisfy the caller.
//   - Or send StatusContinue response before reading request body
//     with ContinueReadBody.
//   - Or close the connection.
//
// io.EOF is returned if r is closed before reading the first header byte.
func (req *Request) Read(r *bufio.Reader) error {
	return req.ReadLimitBody(r, 0)
}

const defaultMaxInMemoryFileSize = 16 * 1024 * 1024

// ErrGetOnly is returned when server expects only GET requests,
// but some other type of request came (Server.GetOnly option is true).
var ErrGetOnly = errors.New("fasthttp: non-get request received")

// ReadLimitBody reads request from the given r, limiting the body size.
//
// If maxBodySize > 0 and the body size exceeds maxBodySize,
// then ErrBodyTooLarge is returned.
// If maxBodySize <= 0, no limit is applied and the request may consume
// unbounded memory.
//
// RemoveMultipartFormFiles or Reset must be called after
// reading multipart/form-data request in order to delete temporarily
// uploaded files.
//
// If MayContinue returns true, the caller must:
//
//   - Either send StatusExpectationFailed response if request headers don't
//     satisfy the caller.
//   - Or send StatusContinue response before reading request body
//     with ContinueReadBody.

View on GitHub (pinned to c96f600972)

Solutions

  1. Remove GetOnly: true from the fasthttp.Server config if non-GET requests are legitimate.
  2. Route non-GET traffic to a different server/port that allows it.
  3. Keep GetOnly and accept the automatic error response; log the method for visibility.
  4. Return a proper 405 in a normal (non-GetOnly) handler if you want custom behavior.

Example fix

// before
server := &fasthttp.Server{Handler: h, GetOnly: true}
// after
server := &fasthttp.Server{Handler: h} // handle methods inside h; 405 if needed
Defensive patterns

Strategy: try-catch

Validate before calling

// client side: only send GET to GetOnly servers
if req.Method() != "GET" && req.Method() != "HEAD" {
    return errors.New("endpoint accepts only GET/HEAD")
}

Try / catch

if errors.Is(err, fasthttp.ErrGetOnly) {
    // endpoint is GET-only; switch method or endpoint
}

Prevention

When it happens

Trigger: Client sends POST/PUT/DELETE etc. to a Server created with GetOnly: true; error surfaces during request reading before your Handler runs.

Common situations: Health-check or static-asset servers built with GetOnly receiving API calls or form submissions; monitoring POSTing results to a GET-only endpoint; bots POSTing to the server.

Related errors


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