cookie

package
v0.9.88 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 15, 2017 License: Apache-2.0, MIT Imports: 5 Imported by: 0

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

View Source
const (
	RequestCookieFilterName    = "requestCookie"
	ResponseCookieFilterName   = "responseCookie"
	ResponseJSCookieFilterName = "jsCookie"
	ChangeOnlyArg              = "change-only"
	SetCookieHttpHeader        = "Set-Cookie"
)

Variables

This section is empty.

Functions

func NewJSCookie

func NewJSCookie() filters.Spec

Creates a filter spec for appending cookies to responses without the HttpOnly directive. Name: jsCookie

func NewRequestCookie

func NewRequestCookie() filters.Spec

Creates a filter spec for appending cookies to requests. Name: requestCookie

func NewResponseCookie

func NewResponseCookie() filters.Spec

Creates a filter spec for appending cookies to responses. Name: responseCookie

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL