valyala/fasthttp · info
fasthttp: no cookies found
Error message
fasthttp: no cookies found
What it means
ErrNoCookies is returned by Response/Header & Cookie parsing helpers when scanning a Cookie header finds no valid cookies at all. The library distinguishes 'nothing to parse' from 'malformed value'. It signals an empty or entirely invalid cookie list.
Source
Thrown at cookie.go:379
c.bufK = c.AppendBytes(c.bufK[:0])
return c.bufK
}
// String returns cookie representation.
func (c *Cookie) String() string {
return string(c.Cookie())
}
// WriteTo writes cookie representation to w.
//
// WriteTo implements io.WriterTo interface.
func (c *Cookie) WriteTo(w io.Writer) (int64, error) {
n, err := w.Write(c.Cookie())
return int64(n), err
}
var (
ErrNoCookies = errors.New("fasthttp: no cookies found")
ErrInvalidCookieValue = errors.New("fasthttp: invalid cookie value")
)
// Parse parses Set-Cookie header.
func (c *Cookie) Parse(src string) error {
c.bufK = append(c.bufK[:0], src...)
return c.ParseBytes(c.bufK)
}
// ParseBytes parses Set-Cookie header.
func (c *Cookie) ParseBytes(src []byte) error {
c.Reset()
var s cookieScanner
s.b = src
var k, v []byte
if !s.nextRaw(&k, &v) {View on GitHub (pinned to c96f600972)
Solutions
- Check whether the Cookie header exists before parsing cookies
- Treat ErrNoCookies as 'no session yet' and proceed to login/set-cookie flow
- Guard iteration with a len check on the raw header value
Example fix
// before
cookies := resp.Header.Cookies() // may return ErrNoCookies
// after
if len(resp.Header.Peek("Cookie")) == 0 {
return nil // no cookies yet, skip parsing
}
cookies := resp.Header.Cookies() Defensive patterns
Strategy: type-guard
Validate before calling
if len(resp.Header.Peek("Cookie")) == 0 {
return nil // nothing to parse
} Type guard
func hasCookies(h *fasthttp.ResponseHeader) bool {
return len(h.Peek("Cookie")) > 0
} Try / catch
if err := parseCookies(h); errors.Is(err, fasthttp.ErrNoCookies) {
return cookieSet{} // empty set is fine
} Prevention
- Check for a Cookie header before iterating cookies
- Model 'no cookies' as an empty set, not an error path
- Set cookies explicitly on first request of a session
When it happens
Trigger: Calling Response.Header.Cookies() / Response.Header.peek of Cookie header when the request/response carries no Cookie header or only whitespace; iterating cookies over an empty header.
Common situations: First request of a session with no cookies set yet; proxies stripping Cookie headers; code assuming cookies always exist after a redirect.
Related errors
- fasthttp: invalid cookie value
- fasthttp: need more data: cannot find trailing lf
- cannot parse content-length: %w
- fasthttp: no args value for the given key
- too large hex number
AI-assisted analysis of valyala/fasthttp@c96f600972 (2026-08-31).
Data as JSON: /api/errors/044feda6478f75e8.
Report an issue: GitHub.