cookie

package
v0.15.7 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package cookie provides a cookie based implementation of session store and loader.

Index

Constants

View Source
const (
	// ChunkedCanaryByte is the byte value used as a canary prefix to distinguish if
	// the cookie is multi-part or not. This constant *should not* be valid
	// base64. It's important this byte is ASCII to avoid UTF-8 variable sized runes.
	// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#Directives
	ChunkedCanaryByte byte = '%'
	// MaxChunkSize sets the upper bound on a cookie chunks payload value.
	// Note, this should be lower than the actual cookie's max size (4096 bytes)
	// which includes metadata.
	MaxChunkSize = 3800
	// MaxNumChunks limits the number of chunks to iterate through. Conservatively
	// set to prevent any abuse.
	MaxNumChunks = 5
)

Variables

This section is empty.

Functions

func NewStore

func NewStore(getOptions GetOptionsFunc, encoder encoding.MarshalUnmarshaler) (sessions.SessionStore, error)

NewStore returns a new store that implements the SessionStore interface using http cookies.

Types

type GetOptionsFunc added in v0.11.0

type GetOptionsFunc func() Options

A GetOptionsFunc is a getter for cookie options.

type Options

type Options struct {
	Name     string
	Domain   string
	Expire   time.Duration
	HTTPOnly bool
	Secure   bool
}

Options holds options for Store

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store implements the session store interface for session cookies.

func NewCookieLoader

func NewCookieLoader(getOptions GetOptionsFunc, dencoder encoding.Unmarshaler) (*Store, error)

NewCookieLoader returns a new store that implements the SessionLoader interface using http cookies.

func (*Store) ClearSession

func (cs *Store) ClearSession(w http.ResponseWriter, r *http.Request)

ClearSession clears the session cookie from a request

func (*Store) LoadSession

func (cs *Store) LoadSession(r *http.Request) (string, error)

LoadSession returns a State from the cookie in the request.

func (*Store) SaveSession

func (cs *Store) SaveSession(w http.ResponseWriter, _ *http.Request, x interface{}) error

SaveSession saves a session state to a request's cookie store.

Jump to

Keyboard shortcuts

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