hasDirective checks if a cache directive header value contains a directive (case-insensitive). A directive is considered matched when followed by end-of-string, ',', ' ', '\t', or '=' per RFC 9111 §5.2.
(cc, directive string)
| 9 | // A directive is considered matched when followed by end-of-string, ',', ' ', '\t', or '=' |
| 10 | // per RFC 9111 §5.2. |
| 11 | func hasDirective(cc, directive string) bool { |
| 12 | ccLen := len(cc) |
| 13 | dirLen := len(directive) |
| 14 | for i := 0; i <= ccLen-dirLen; i++ { |
| 15 | if !utils.EqualFold(cc[i:i+dirLen], directive) { |
| 16 | continue |
| 17 | } |
| 18 | if i > 0 { |
| 19 | prev := cc[i-1] |
| 20 | if prev != ' ' && prev != ',' && prev != '\t' { |
| 21 | continue |
| 22 | } |
| 23 | } |
| 24 | if i+dirLen == ccLen { |
| 25 | return true |
| 26 | } |
| 27 | next := cc[i+dirLen] |
| 28 | if next == ',' || next == ' ' || next == '\t' || next == '=' { |
| 29 | return true |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | return false |
| 34 | } |
| 35 | |
| 36 | func parseUintDirective(val []byte) (uint64, bool) { |
| 37 | if len(val) == 0 { |
no outgoing calls