cookie

package
v0.30.0 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2026 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FilterAuthCookies

func FilterAuthCookies(cookies []*http.Cookie, authHost string) []*http.Cookie

FilterAuthCookies returns cookies that belong to the auth hostname.

func Load

func Load(filename string) ([]*http.Cookie, error)

Load reads cookies from a Netscape format file.

func LoadUser

func LoadUser(filename string) string

LoadUser reads the username from a cookie file if present. Returns empty string if no username is found or file doesn't exist.

func MatchDomain

func MatchDomain(cookieDomain, targetDomain string) bool

MatchDomain checks if a cookie domain matches the target domain. Cookie domain ".example.com" matches "sub.example.com" and "example.com". Cookie domain "example.com" matches only "example.com".

func PrintStatus

func PrintStatus(cookies []*http.Cookie, asJSON bool, verified bool, verifiedValid bool, w io.Writer)

PrintStatus displays cookie information in either table or JSON format. If asJSON is true, output is in JSON format. Otherwise, a formatted table is shown. If verified is true, shows verification status instead of time-based expiry.

func VerifyCookies

func VerifyCookies(targetURL, authHost string, cookies []*http.Cookie, verifyCert bool) (bool, time.Duration)

VerifyCookies checks if cookies are valid for the target URL. Returns (valid, remainingDuration) tuple.

Types

type CookieStatusJSON

type CookieStatusJSON struct {
	Name             string  `json:"name"`
	Domain           string  `json:"domain"`
	Path             string  `json:"path"`
	Secure           bool    `json:"secure"`
	HttpOnly         bool    `json:"http_only"`
	Expires          *string `json:"expires"`
	Status           string  `json:"status"`
	RemainingSeconds float64 `json:"remaining_seconds"`
	Verified         bool    `json:"verified"`
	VerifiedValid    bool    `json:"verified_valid,omitempty"`
}

CookieStatusJSON represents cookie data for JSON output.

type Jar

type Jar struct {
	*cookiejar.Jar
}

Jar wraps http.CookieJar with persistence to Netscape format.

func NewJar

func NewJar() (*Jar, error)

NewJar creates a new cookie jar.

func (*Jar) Save

func (j *Jar) Save(filename string, cookies []*http.Cookie, domain string) error

Save writes cookies to a file in Netscape format.

func (*Jar) SaveWithUser

func (j *Jar) SaveWithUser(filename string, cookies []*http.Cookie, domain string, username string) error

SaveWithUser writes cookies to a file in Netscape format with username tracking. If username is provided, it's stored as a comment for later validation.

func (*Jar) SetCookiesFromSlice

func (j *Jar) SetCookiesFromSlice(u *url.URL, cookies []*http.Cookie)

SetCookiesFromSlice sets cookies on the jar for a given URL.

func (*Jar) Update

func (j *Jar) Update(filename string, newCookies []*http.Cookie, domain string) error

Update reads the existing cookies from the file, removes expired ones, updates with the new cookies (replacing conflicts), and saves the result. The domain parameter is used as a fallback for cookies without a domain set.

func (*Jar) UpdateWithUser

func (j *Jar) UpdateWithUser(filename string, newCookies []*http.Cookie, domain string, username string) error

UpdateWithUser is like Update but also stores the username in the file. If username is empty, it preserves any existing username from the file.

Jump to

Keyboard shortcuts

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