Documentation ¶
Overview ¶
Package cookie implements filters to append to requests or responses.
It implements two filters, one for appending cookies to requests in the "Cookie" header, and one for appending cookies to responses in the "Set-Cookie" header.
Both the request and response cookies expect a name and a value argument.
The response cookie accepts an optional argument to control the max-age property of the cookie, of type number, in seconds.
The response cookie accepts an optional fourth argument, "change-only", to control if the cookie should be set on every response, or only if the request doesn't contain a cookie with the provided name and value. If the fourth argument is "change-only", and a cookie with the same name and value is found in the request, the cookie is not set. This argument can be used to disable sliding TTL of the cookie.
The JS cookie behaves exactly as the response cookie, but it doesn't set the HttpOnly directive, so these cookies will be accessible from JS code running in web browsers.
Examples:
requestCookie("test-session", "abc") responseCookie("test-session", "abc", 31536000) responseCookie("test-session", "abc", 31536000, "change-only") // response cookie without HttpOnly: jsCookie("test-session-info", "abc-debug", 31536000, "change-only")
Index ¶
Constants ¶
const ( // Deprecated, use filters.RequestCookieName instead RequestCookieFilterName = filters.RequestCookieName // Deprecated, use filters.ResponseCookieName instead ResponseCookieFilterName = filters.ResponseCookieName // Deprecated, use filters.JsCookieName instead ResponseJSCookieFilterName = filters.JsCookieName ChangeOnlyArg = "change-only" SetCookieHttpHeader = "Set-Cookie" )
Variables ¶
This section is empty.
Functions ¶
func NewDropRequestCookie ¶ added in v0.16.112
func NewDropResponseCookie ¶ added in v0.16.112
func NewJSCookie ¶
Creates a filter spec for appending cookies to responses without the HttpOnly directive. Name: jsCookie
func NewRequestCookie ¶
Creates a filter spec for appending cookies to requests. Name: requestCookie
func NewResponseCookie ¶
Creates a filter spec for appending cookies to responses. Name: responseCookie
Types ¶
This section is empty.