session

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// These limits apply to persistent session state. The file limit bounds
	// input before JSON decoding; the serialized limit bounds the cookie data
	// itself before an atomic save.
	MaxSessionFileBytes       = 2 << 20
	MaxSessionCookies         = 2048
	MaxCookiesPerDomain       = 64
	MaxCookieNameBytes        = 256
	MaxCookieValueBytes       = 4096
	MaxSerializedSessionBytes = 1 << 20
)

Variables

This section is empty.

Functions

func IsValidName

func IsValidName(name string) bool

IsValidName returns true if the session name contains only alphanumeric characters, hyphens, and underscores.

Types

type Session

type Session struct {
	Name    string
	Cookies []SessionCookie
	// contains filtered or unexported fields
}

Session represents a named cookie session.

func Load

func Load(name string) (*Session, error)

Load loads a session from disk or creates a new empty session. Expired cookies are filtered out on load.

func LoadReadOnly added in v0.28.0

func LoadReadOnly(name string) (*Session, error)

LoadReadOnly loads a session without creating or modifying its directory. It is used by dry-run so presentation can include existing cookies without changing session state merely because the configured directory is absent.

func (*Session) Jar

func (s *Session) Jar() http.CookieJar

Jar returns an http.CookieJar that persists cookies to this session.

func (*Session) Save

func (s *Session) Save() error

Save merges this session's changes with the latest on-disk state and then atomically commits the result. This prevents concurrent fetch processes from losing cookie updates or deletions.

func (*Session) TakeDiagnostics added in v0.28.0

func (s *Session) TakeDiagnostics() []string

TakeDiagnostics returns and clears bounded diagnostics generated while response cookies were processed or a session was saved.

type SessionCookie

type SessionCookie struct {
	Name     string    `json:"name"`
	Value    string    `json:"value"`
	Domain   string    `json:"domain"`
	HostOnly bool      `json:"host_only,omitzero"`
	Path     string    `json:"path,omitzero"`
	Expires  time.Time `json:"expires,omitzero"`
	Secure   bool      `json:"secure,omitzero"`
	HttpOnly bool      `json:"http_only,omitzero"`
	SameSite string    `json:"same_site,omitzero"`
}

SessionCookie represents a JSON-serializable cookie.

Jump to

Keyboard shortcuts

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