Cookies is a middleware that allows handling of secure cookies.
(hashKey, blockKey []byte)
| 28 | |
| 29 | // Cookies is a middleware that allows handling of secure cookies. |
| 30 | func Cookies(hashKey, blockKey []byte) MiddlewareFunc { |
| 31 | s := securecookie.New(hashKey, blockKey) |
| 32 | return func(next http.Handler) http.Handler { |
| 33 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 34 | ctx := r.Context() |
| 35 | ctx = context.WithValue(ctx, secureCookieCtxKey, s) |
| 36 | next.ServeHTTP(w, r.WithContext(ctx)) |
| 37 | }) |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | var errInvalidContext = errors.DefineInternal("secure_cookie_invalid_context", "No secure cookie value in this context") |
| 42 |