valyala/fasthttp · error
fasthttp: error when reading response headers
Error message
fasthttp: error when reading response headers
What it means
ErrReadingResponseHeaders indicates fasthttp failed while parsing an HTTP response's header section from the wire — malformed start line, invalid header syntax, or truncated input. It is an exported sentinel from header.go used (possibly wrapped) when header parsing errors occur.
Source
Thrown at header.go:470
// 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:
// 1. necessary for message framing (e.g., Transfer-Encoding and Content-Length),
// 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.View on GitHub (pinned to c96f600972)
Solutions
- Verify the endpoint scheme/port (https:// vs http://) matches the server
- Inspect the raw response (curl -v) to see what the server actually sends
- Check for intercepting proxies/VPN/CDN mangling responses and set proper Proxy settings
- Increase ReadTimeout/retry, or upgrade fasthttp if parsing a valid but unusual header fails
Defensive patterns
Strategy: try-catch
Validate before calling
// verify endpoint scheme/port before requesting
u, _ := url.Parse(target)
if u.Scheme == "https" && !clientTLS { return errors.New("client not configured for TLS") } Try / catch
err := client.Do(req, resp)
if err != nil {
if errors.Is(err, fasthttp.ErrReadingResponseHeaders) {
// log raw bytes, check scheme/proxy, retry once
}
} Prevention
- Match URL scheme to server protocol (https vs http vs h2c)
- Bypass or correctly configure proxies/CDNs that inject HTML errors
- Set sane ReadTimeout and retry transient failures
- curl -v the endpoint to see the exact bytes the server returns
When it happens
Trigger: Client calls (Do/DoTimeout/DoRedirect) receiving a response whose header bytes are malformed: missing space in status line, non-ASCII/garbage bytes, connection closed mid-headers, or a non-HTTP proxy response.
Common situations: Target server is actually speaking TLS to a plain-HTTP client (or vice versa); intermediate proxies/CDNs returning HTML error pages; UDP/TCP misrouting; server sending HTTP/2 to an HTTP/1.1-only client.
Related errors
- fasthttp: contain forbidden trailer
- fasthttp: error when reading response trailer
- fasthttp: cannot find whitespace in the first line of respon
- fasthttp: unexpected char at the end of status code
- cannot find whitespace in the first line of response %q
AI-assisted analysis of valyala/fasthttp@c96f600972 (2026-08-31).
Data as JSON: /api/errors/b26b88489ce03bfe.
Report an issue: GitHub.