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)
| 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). |
| 53 | func 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 |