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.
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")
const ( RequestCookieFilterName = "requestCookie" ResponseCookieFilterName = "responseCookie" ResponseJSCookieFilterName = "jsCookie" ChangeOnlyArg = "change-only" SetCookieHttpHeader = "Set-Cookie" )
Creates a filter spec for appending cookies to responses without the HttpOnly directive. Name: jsCookie
Creates a filter spec for appending cookies to requests. Name: requestCookie
Creates a filter spec for appending cookies to responses. Name: responseCookie