MCPcopy
hub / github.com/gin-gonic/gin / SetCookie

Method SetCookie

context.go:1109–1123  ·  view source on GitHub ↗

SetCookie adds a Set-Cookie header to the ResponseWriter's headers. The provided cookie must have a valid Name. Invalid cookies may be silently dropped.

(name, value string, maxAge int, path, domain string, secure, httpOnly bool)

Source from the content-addressed store, hash-verified

1107// The provided cookie must have a valid Name. Invalid cookies may be
1108// silently dropped.
1109func (c *Context) SetCookie(name, value string, maxAge int, path, domain string, secure, httpOnly bool) {
1110 if path == "" {
1111 path = "/"
1112 }
1113 http.SetCookie(c.Writer, &http.Cookie{
1114 Name: name,
1115 Value: url.QueryEscape(value),
1116 MaxAge: maxAge,
1117 Path: path,
1118 Domain: domain,
1119 SameSite: c.sameSite,
1120 Secure: secure,
1121 HttpOnly: httpOnly,
1122 })
1123}
1124
1125// SetCookieData adds a Set-Cookie header to the ResponseWriter's headers.
1126// It accepts a pointer to http.Cookie structure for more flexibility in setting cookie attributes.

Callers 3

TestContextSetCookieFunction · 0.80
SetCookieDataMethod · 0.80

Calls

no outgoing calls

Tested by 2

TestContextSetCookieFunction · 0.64