MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / Cookies

Function Cookies

pkg/webmiddleware/cookie.go:30–39  ·  view source on GitHub ↗

Cookies is a middleware that allows handling of secure cookies.

(hashKey, blockKey []byte)

Source from the content-addressed store, hash-verified

28
29// Cookies is a middleware that allows handling of secure cookies.
30func 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
41var errInvalidContext = errors.DefineInternal("secure_cookie_invalid_context", "No secure cookie value in this context")
42

Callers 4

NewFunction · 0.92
TestCookieFunction · 0.92
TestCookiesFunction · 0.85
TestCookieAuthFunction · 0.85

Calls 3

NewMethod · 0.65
ContextMethod · 0.65
ServeHTTPMethod · 0.45

Tested by 3

TestCookieFunction · 0.74
TestCookiesFunction · 0.68
TestCookieAuthFunction · 0.68