session

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSessionClosed = errors.New("session is closed")
)

Functions

This section is empty.

Types

type Manager

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

Manager manages all active sessions

func NewManager

func NewManager() *Manager

NewManager creates a new session manager

func (*Manager) CloseSession

func (m *Manager) CloseSession(sessionID string) error

CloseSession closes and removes a session

func (*Manager) CreateSession

func (m *Manager) CreateSession(config *protocol.SessionConfig) (string, error)

CreateSession creates a new session and returns its ID

func (*Manager) GetSession

func (m *Manager) GetSession(sessionID string) (*Session, error)

GetSession retrieves a session by ID

func (*Manager) ListSessions

func (m *Manager) ListSessions() []SessionStats

ListSessions returns stats for all active sessions

func (*Manager) SessionCount

func (m *Manager) SessionCount() int

SessionCount returns the number of active sessions

func (*Manager) SetMaxSessions

func (m *Manager) SetMaxSessions(max int)

SetMaxSessions sets the maximum number of concurrent sessions

func (*Manager) SetSessionTimeout

func (m *Manager) SetSessionTimeout(timeout time.Duration)

SetSessionTimeout sets the session idle timeout

func (*Manager) Shutdown

func (m *Manager) Shutdown()

Shutdown closes all sessions and stops the manager

type Session

type Session struct {
	ID           string
	CreatedAt    time.Time
	LastUsed     time.Time
	RequestCount int64
	Config       *protocol.SessionConfig
	// contains filtered or unexported fields
}

Session represents a persistent HTTP session with connection affinity

func NewSession

func NewSession(id string, config *protocol.SessionConfig) *Session

NewSession creates a new session with its own connection pool

func (*Session) ClearCache

func (s *Session) ClearCache()

ClearCache clears all cached URLs (removes If-None-Match/If-Modified-Since headers)

func (*Session) ClearCookies

func (s *Session) ClearCookies()

ClearCookies removes all cookies from this session

func (*Session) Close

func (s *Session) Close()

Close marks the session as inactive and closes connections

func (*Session) Get

func (s *Session) Get(ctx context.Context, url string, headers map[string]string) (*transport.Response, error)

Get performs a GET request

func (*Session) GetCookies

func (s *Session) GetCookies() map[string]string

GetCookies returns all cookies for this session

func (*Session) GetTransport

func (s *Session) GetTransport() *transport.Transport

GetTransport returns the session's transport

func (*Session) IdleTime

func (s *Session) IdleTime() time.Duration

IdleTime returns how long since the session was last used

func (*Session) IsActive

func (s *Session) IsActive() bool

IsActive returns whether the session is active

func (*Session) Post

func (s *Session) Post(ctx context.Context, url string, body []byte, headers map[string]string) (*transport.Response, error)

Post performs a POST request

func (*Session) Request

func (s *Session) Request(ctx context.Context, req *transport.Request) (*transport.Response, error)

Request executes an HTTP request within this session

func (*Session) SetCookie

func (s *Session) SetCookie(name, value string)

SetCookie sets a cookie for this session

func (*Session) SetCookies

func (s *Session) SetCookies(cookies map[string]string)

SetCookies sets multiple cookies for this session

func (*Session) Stats

func (s *Session) Stats() SessionStats

Stats returns session statistics

func (*Session) Touch

func (s *Session) Touch()

Touch updates the last used timestamp

type SessionStats

type SessionStats struct {
	ID              string
	Preset          string
	CreatedAt       time.Time
	LastUsed        time.Time
	RequestCount    int64
	Active          bool
	CookieCount     int
	CacheEntryCount int // Number of cached URLs (for If-None-Match/If-Modified-Since)
	Age             time.Duration
	IdleTime        time.Duration
	TransportStats  map[string]interface{}
}

SessionStats contains session statistics

Jump to

Keyboard shortcuts

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