MCPcopy
hub / github.com/gofiber/fiber / hasFlashCookie

Function hasFlashCookie

redirect.go:53–64  ·  view source on GitHub ↗

hasFlashCookie is on the request hot path and runs on every request/response cycle. Keep this cheap for users who don't use flash messages: 1) a fast raw-header prefilter to avoid unnecessary cookie parsing, 2) an exact cookie lookup to avoid prefix false positives (e.g. fiber_flashX).

(header *fasthttp.RequestHeader)

Source from the content-addressed store, hash-verified

51// 1) a fast raw-header prefilter to avoid unnecessary cookie parsing,
52// 2) an exact cookie lookup to avoid prefix false positives (e.g. fiber_flashX).
53func hasFlashCookie(header *fasthttp.RequestHeader) bool {
54 rawHeaders := header.RawHeaders()
55 if len(rawHeaders) == 0 {
56 return false
57 }
58
59 if !bytes.Contains(rawHeaders, flashCookieNeedle) {
60 return false
61 }
62
63 return header.Cookie(FlashCookieName) != nil
64}
65
66// redirectionMsgs is a struct that used to store flash messages and old input data in cookie using MSGP.
67// msgp -file="redirect.go" -o="redirect_msgp.go" -unexported

Callers 3

defaultRequestHandlerMethod · 0.85
customRequestHandlerMethod · 0.85

Calls 2

ContainsMethod · 0.80
CookieMethod · 0.65

Tested by 1