MCPcopy Create free account
hub / github.com/kataras/iris / CookieEncoding

Function CookieEncoding

context/context.go:5779–5812  ·  view source on GitHub ↗

CookieEncoding accepts a value which implements `Encode` and `Decode` methods. It calls its `Encode` on `Context.SetCookie, UpsertCookie, and SetCookieKV` methods. And on `Context.GetCookie` method it calls its `Decode`. If "cookieNames" slice is not empty then only cookies with that `Name` will be

(encoding SecureCookie, cookieNames ...string)

Source from the content-addressed store, hash-verified

5777//
5778// Example: https://github.com/kataras/iris/tree/main/_examples/cookies/securecookie
5779func CookieEncoding(encoding SecureCookie, cookieNames ...string) CookieOption {
5780 if encoding == nil {
5781 return func(_ *Context, _ *http.Cookie, _ uint8) {}
5782 }
5783
5784 return func(ctx *Context, c *http.Cookie, op uint8) {
5785 if op == OpCookieDel {
5786 return
5787 }
5788
5789 if !CookieIncluded(c, cookieNames) {
5790 return
5791 }
5792
5793 switch op {
5794 case OpCookieSet:
5795 // Should encode, it's a write to the client operation.
5796 newVal, err := encoding.Encode(c.Name, c.Value)
5797 if err != nil {
5798 ctx.Application().Logger().Error(err)
5799 c.Value = ""
5800 } else {
5801 c.Value = newVal
5802 }
5803
5804 return
5805 case OpCookieGet:
5806 // Should decode, it's a read from the client operation.
5807 if err := encoding.Decode(c.Name, c.Value, &c.Value); err != nil {
5808 c.Value = ""
5809 }
5810 }
5811 }
5812}
5813
5814const cookieOptionsContextKey = "iris.cookie.options"
5815

Callers 3

NewFunction · 0.92
ExtractAccessTokenMethod · 0.92
trySetCookieMethod · 0.92

Calls 6

CookieIncludedFunction · 0.85
EncodeMethod · 0.80
ApplicationMethod · 0.80
ErrorMethod · 0.65
LoggerMethod · 0.65
DecodeMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…