Documentation
¶
Overview ¶
Package session provides session management for persisting cookies and variables across HTTP requests, supporting both directory-scoped and named session modes.
Index ¶
- func ClearAllSessions(baseDir string) error
- func ClearAllSessionsWithFS(fs filesystem.FileSystem, baseDir string) error
- func ListAllSessions(baseDir string) ([]string, error)
- func ListAllSessionsWithFS(fs filesystem.FileSystem, baseDir string) ([]string, error)
- func SaveEnvironmentStore(fs filesystem.FileSystem, sessionDir string, store *EnvironmentStore) error
- func SaveSessionConfig(fs filesystem.FileSystem, sessionDir string, cfg *SessionConfig) error
- type Cookie
- type EnvironmentStore
- func (s *EnvironmentStore) AddEnvironment(name string, vars map[string]string) error
- func (s *EnvironmentStore) GetEnvironment(env string) map[string]string
- func (s *EnvironmentStore) GetVariable(env, name string) (string, bool)
- func (s *EnvironmentStore) GetVariables(env string) (map[string]string, bool)
- func (s *EnvironmentStore) HasEnvironment(name string) bool
- func (s *EnvironmentStore) ListEnvironments() []string
- func (s *EnvironmentStore) RemoveEnvironment(name string) error
- func (s *EnvironmentStore) SetVariable(env, name, value string) error
- func (s *EnvironmentStore) UnsetVariable(env, name string) error
- type SessionCertificateBlock
- type SessionConfig
- type SessionEnvironmentBlock
- type SessionHTTPBlock
- type SessionManager
- func (s *SessionManager) ClearAll()
- func (s *SessionManager) ClearCookies()
- func (s *SessionManager) ClearVariables()
- func (s *SessionManager) Delete() error
- func (s *SessionManager) GetAllCookies() map[string][]Cookie
- func (s *SessionManager) GetAllVariables() map[string]any
- func (s *SessionManager) GetCookiesForURL(urlStr string) []*http.Cookie
- func (s *SessionManager) GetSessionPath() string
- func (s *SessionManager) GetVariable(name string) (any, bool)
- func (s *SessionManager) GetVariableAsString(name string) (string, bool)
- func (s *SessionManager) Load() error
- func (s *SessionManager) LoadCookies() error
- func (s *SessionManager) LoadVariables() error
- func (s *SessionManager) Save() error
- func (s *SessionManager) SaveCookies() error
- func (s *SessionManager) SaveVariables() error
- func (s *SessionManager) SetCookiesFromResponse(urlStr string, cookies []*http.Cookie)
- func (s *SessionManager) SetVariable(name string, value any)
- type SessionTLSBlock
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClearAllSessions ¶
ClearAllSessions removes all session data
func ClearAllSessionsWithFS ¶ added in v0.2.10
func ClearAllSessionsWithFS(fs filesystem.FileSystem, baseDir string) error
ClearAllSessionsWithFS removes all session data using a custom file system.
func ListAllSessions ¶
ListAllSessions returns all session directories
func ListAllSessionsWithFS ¶ added in v0.2.10
func ListAllSessionsWithFS(fs filesystem.FileSystem, baseDir string) ([]string, error)
ListAllSessionsWithFS returns all session directories using a custom file system.
func SaveEnvironmentStore ¶ added in v0.2.20
func SaveEnvironmentStore(fs filesystem.FileSystem, sessionDir string, store *EnvironmentStore) error
SaveEnvironmentStore persists the environment store to disk.
func SaveSessionConfig ¶ added in v0.2.20
func SaveSessionConfig(fs filesystem.FileSystem, sessionDir string, cfg *SessionConfig) error
SaveSessionConfig persists the provided session config to disk.
Types ¶
type Cookie ¶
type Cookie struct {
Name string `json:"name"`
Value string `json:"value"`
Path string `json:"path,omitempty"`
Domain string `json:"domain,omitempty"`
Expires time.Time `json:"expires,omitempty"`
MaxAge int `json:"maxAge,omitempty"`
Secure bool `json:"secure,omitempty"`
HttpOnly bool `json:"httpOnly,omitempty"`
SameSite string `json:"sameSite,omitempty"`
}
Cookie represents a serializable cookie
type EnvironmentStore ¶ added in v0.2.20
type EnvironmentStore struct {
Version int `json:"version"`
EnvironmentVariables map[string]map[string]string `json:"environmentVariables"`
}
EnvironmentStore manages per-session environment variables.
func LoadOrCreateEnvironmentStore ¶ added in v0.2.20
func LoadOrCreateEnvironmentStore(fs filesystem.FileSystem, sessionDir string) (*EnvironmentStore, error)
LoadOrCreateEnvironmentStore loads an existing environment store or recreates it with defaults.
func (*EnvironmentStore) AddEnvironment ¶ added in v0.2.20
func (s *EnvironmentStore) AddEnvironment(name string, vars map[string]string) error
AddEnvironment adds a new named environment.
func (*EnvironmentStore) GetEnvironment ¶ added in v0.2.20
func (s *EnvironmentStore) GetEnvironment(env string) map[string]string
GetEnvironment returns the merged environment map combining $shared and the named environment.
func (*EnvironmentStore) GetVariable ¶ added in v0.2.20
func (s *EnvironmentStore) GetVariable(env, name string) (string, bool)
GetVariable returns a specific variable value.
func (*EnvironmentStore) GetVariables ¶ added in v0.2.20
func (s *EnvironmentStore) GetVariables(env string) (map[string]string, bool)
GetVariables returns the raw variables for an environment.
func (*EnvironmentStore) HasEnvironment ¶ added in v0.2.20
func (s *EnvironmentStore) HasEnvironment(name string) bool
HasEnvironment reports whether the environment exists.
func (*EnvironmentStore) ListEnvironments ¶ added in v0.2.20
func (s *EnvironmentStore) ListEnvironments() []string
ListEnvironments returns all named environments excluding $shared.
func (*EnvironmentStore) RemoveEnvironment ¶ added in v0.2.20
func (s *EnvironmentStore) RemoveEnvironment(name string) error
RemoveEnvironment removes a named environment.
func (*EnvironmentStore) SetVariable ¶ added in v0.2.20
func (s *EnvironmentStore) SetVariable(env, name, value string) error
SetVariable sets a variable within an environment.
func (*EnvironmentStore) UnsetVariable ¶ added in v0.2.20
func (s *EnvironmentStore) UnsetVariable(env, name string) error
UnsetVariable removes a variable from an environment.
type SessionCertificateBlock ¶ added in v0.2.20
type SessionCertificateBlock struct {
Cert string `json:"cert,omitempty"`
Key string `json:"key,omitempty"`
PFX string `json:"pfx,omitempty"`
Passphrase string `json:"passphrase,omitempty"`
}
SessionCertificateBlock stores certificate references for a host.
type SessionConfig ¶ added in v0.2.20
type SessionConfig struct {
Version int `json:"version"`
Environment SessionEnvironmentBlock `json:"environment"`
HTTP SessionHTTPBlock `json:"http"`
TLS SessionTLSBlock `json:"tls"`
}
SessionConfig represents session-scoped configuration that travels with a session directory.
func DefaultSessionConfig ¶ added in v0.2.20
func DefaultSessionConfig() *SessionConfig
DefaultSessionConfig returns a new session config with default values (exported for testing/fallback)
func LoadOrCreateSessionConfig ¶ added in v0.2.20
func LoadOrCreateSessionConfig(fs filesystem.FileSystem, sessionDir string) (*SessionConfig, error)
LoadOrCreateSessionConfig loads an existing session config or recreates it with defaults.
func (*SessionConfig) CurrentEnvironment ¶ added in v0.2.20
func (c *SessionConfig) CurrentEnvironment() string
CurrentEnvironment returns the current environment name
func (*SessionConfig) DefaultHeaders ¶ added in v0.2.20
func (c *SessionConfig) DefaultHeaders() map[string]string
DefaultHeaders returns the default headers map
func (*SessionConfig) RememberCookies ¶ added in v0.2.20
func (c *SessionConfig) RememberCookies() bool
RememberCookies returns whether cookies should be persisted
func (*SessionConfig) SetCurrentEnvironment ¶ added in v0.2.20
func (c *SessionConfig) SetCurrentEnvironment(env string)
SetCurrentEnvironment sets the current environment name
func (*SessionConfig) ToClientConfig ¶ added in v0.2.20
func (c *SessionConfig) ToClientConfig() *client.ClientConfig
ToClientConfig converts SessionConfig to client.ClientConfig for HTTP requests
type SessionEnvironmentBlock ¶ added in v0.2.20
type SessionEnvironmentBlock struct {
Current string `json:"current"`
RememberCookies bool `json:"rememberCookiesForSubsequentRequests"`
DefaultHeaders map[string]string `json:"defaultHeaders"`
}
SessionEnvironmentBlock contains environment-specific settings.
type SessionHTTPBlock ¶ added in v0.2.20
type SessionHTTPBlock struct {
TimeoutMs int `json:"timeoutInMilliseconds"`
FollowRedirect bool `json:"followRedirect"`
CookieJar string `json:"cookieJar"`
}
SessionHTTPBlock controls HTTP client behaviour for a session.
type SessionManager ¶
type SessionManager struct {
// contains filtered or unexported fields
}
SessionManager manages session persistence for cookies and variables
func NewSessionManager ¶
func NewSessionManager(baseDir, httpFilePath, sessionName string) (*SessionManager, error)
NewSessionManager creates a new session manager If sessionName is provided, uses named session; otherwise uses directory-based session
func NewSessionManagerWithFS ¶ added in v0.2.10
func NewSessionManagerWithFS(fs filesystem.FileSystem, baseDir, httpFilePath, sessionName string) (*SessionManager, error)
NewSessionManagerWithFS creates a new session manager with a custom file system. This is primarily useful for testing.
func (*SessionManager) ClearAll ¶
func (s *SessionManager) ClearAll()
ClearAll clears both cookies and variables
func (*SessionManager) ClearCookies ¶
func (s *SessionManager) ClearCookies()
ClearCookies clears all cookies
func (*SessionManager) ClearVariables ¶
func (s *SessionManager) ClearVariables()
ClearVariables clears all variables
func (*SessionManager) Delete ¶
func (s *SessionManager) Delete() error
Delete removes the session directory from disk
func (*SessionManager) GetAllCookies ¶
func (s *SessionManager) GetAllCookies() map[string][]Cookie
GetAllCookies returns all cookies
func (*SessionManager) GetAllVariables ¶
func (s *SessionManager) GetAllVariables() map[string]any
GetAllVariables returns all session variables
func (*SessionManager) GetCookiesForURL ¶
func (s *SessionManager) GetCookiesForURL(urlStr string) []*http.Cookie
GetCookiesForURL returns cookies for a given URL
func (*SessionManager) GetSessionPath ¶
func (s *SessionManager) GetSessionPath() string
GetSessionPath returns the session path (for display purposes)
func (*SessionManager) GetVariable ¶
func (s *SessionManager) GetVariable(name string) (any, bool)
GetVariable gets a session variable
func (*SessionManager) GetVariableAsString ¶
func (s *SessionManager) GetVariableAsString(name string) (string, bool)
GetVariableAsString gets a session variable as string
func (*SessionManager) Load ¶
func (s *SessionManager) Load() error
Load loads both cookies and variables from disk
func (*SessionManager) LoadCookies ¶
func (s *SessionManager) LoadCookies() error
LoadCookies loads cookies from disk
func (*SessionManager) LoadVariables ¶
func (s *SessionManager) LoadVariables() error
LoadVariables loads variables from disk
func (*SessionManager) Save ¶
func (s *SessionManager) Save() error
Save saves both cookies and variables to disk
func (*SessionManager) SaveCookies ¶
func (s *SessionManager) SaveCookies() error
SaveCookies saves cookies to disk
func (*SessionManager) SaveVariables ¶
func (s *SessionManager) SaveVariables() error
SaveVariables saves variables to disk
func (*SessionManager) SetCookiesFromResponse ¶
func (s *SessionManager) SetCookiesFromResponse(urlStr string, cookies []*http.Cookie)
SetCookiesFromResponse stores cookies from an HTTP response
func (*SessionManager) SetVariable ¶
func (s *SessionManager) SetVariable(name string, value any)
SetVariable sets a session variable
type SessionTLSBlock ¶ added in v0.2.20
type SessionTLSBlock struct {
InsecureSSL bool `json:"insecureSSL"`
Proxy string `json:"proxy"`
ExcludeHostsForProxy []string `json:"excludeHostsForProxy"`
Certificates map[string]SessionCertificateBlock `json:"certificates"`
}
SessionTLSBlock mirrors TLS/proxy options at the session scope.