CookieAllowReclaim accepts the Context itself. If set it will add the cookie to (on `CookieSet`, `CookieSetKV`, `CookieUpsert`) or remove the cookie from (on `CookieRemove`) the Request object too.
(cookieNames ...string)
| 5628 | // If set it will add the cookie to (on `CookieSet`, `CookieSetKV`, `CookieUpsert`) |
| 5629 | // or remove the cookie from (on `CookieRemove`) the Request object too. |
| 5630 | func CookieAllowReclaim(cookieNames ...string) CookieOption { |
| 5631 | return func(ctx *Context, c *http.Cookie, op uint8) { |
| 5632 | if op == OpCookieGet { |
| 5633 | return |
| 5634 | } |
| 5635 | |
| 5636 | if !CookieIncluded(c, cookieNames) { |
| 5637 | return |
| 5638 | } |
| 5639 | |
| 5640 | switch op { |
| 5641 | case OpCookieSet: |
| 5642 | // perform upsert on request cookies or is it too much and not worth the cost? |
| 5643 | ctx.Request().AddCookie(c) |
| 5644 | case OpCookieDel: |
| 5645 | cookies := ctx.Request().Cookies() |
| 5646 | ctx.Request().Header.Del("Cookie") |
| 5647 | for i, v := range cookies { |
| 5648 | if v.Name != c.Name { |
| 5649 | ctx.Request().AddCookie(cookies[i]) |
| 5650 | } |
| 5651 | } |
| 5652 | } |
| 5653 | } |
| 5654 | } |
| 5655 | |
| 5656 | // CookieAllowSubdomains set to the Cookie Options |
| 5657 | // in order to allow subdomains to have access to the cookies. |
no test coverage detected
searching dependent graphs…