cookiejar

package
v5.3.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2017 License: BSD-3-Clause, BSD-3-Clause Imports: 11 Imported by: 12

Documentation

Overview

Package cookiejar implements an in-memory RFC 6265-compliant http.CookieJar. It is a drop-in replacement for net/http/cookiejar which allows to inspect the content of the Jar.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	Name       string
	Value      string
	Domain     string
	Path       string
	Secure     bool
	HttpOnly   bool
	Persistent bool
	HostOnly   bool
	Expires    time.Time
	Creation   time.Time
	LastAccess time.Time
	// contains filtered or unexported fields
}

Entry is the representation of a cookie in the jar. The exported fields are those of RFC 6265.

func (*Entry) ID

func (e *Entry) ID() string

ID returns the domain;path;name triple of e as an id.

type Jar

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

Jar implements the http.CookieJar interface from the net/http package.

func New

func New(o *Options) (*Jar, error)

New returns a new cookie jar. A nil *Options is equivalent to a zero Options.

func (*Jar) Cookies

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

Cookies implements the Cookies method of the http.CookieJar interface.

It returns an empty slice if the URL's scheme is not HTTP or HTTPS.

func (*Jar) ETLDsPlus1

func (j *Jar) ETLDsPlus1(dst []string) []string

ETLDsPlus1 appends all effective top level domains + 1 or the IP address for which cookies are stored to dst and returns the extended slice.

func (*Jar) Entries

func (j *Jar) Entries(eTLDplus1 string, dst []Entry) []Entry

Entries appends all jar entries stored for the given eTLD+1 to dst and returns the extended slice. The result set may be empty even if the eTLD+1 was reported by ETLDsPlus1, e.g. because cookies have expired.

func (*Jar) LoadEntries

func (j *Jar) LoadEntries(entries []Entry)

LoadEntries stores the values in entries in the jar j. Existing entries are updated. Invalied entries like expired entries or entries not acceptable due to the public suffix list in use are dropped silently. LoadEntries does not generate modification notifications on the Notify channel.

func (*Jar) SetCookies

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

SetCookies implements the SetCookies method of the http.CookieJar interface.

It does nothing if the URL's scheme is not HTTP or HTTPS.

type Notification

type Notification uint32

Notification is a bitmap of possible notification events generated by the Jar.

const (
	ReadAccess   Notification = 1 << iota // LastAccess modified in Cookies().
	Expiration                            // Deleted because expiration detected in Cookies().
	DeleteCookie                          // Deleted during SetCookies.
	SetCookie                             // Set or updated during SetCookies.
)

Types of possible Notifications

type Options

type Options struct {
	// PublicSuffixList is the public suffix list that determines whether
	// an HTTP server can set a cookie for a domain.
	//
	// A nil value is valid and may be useful for testing but it is not
	// secure: it means that the HTTP server for foo.co.uk can set a cookie
	// for bar.co.uk.
	PublicSuffixList cookiejar.PublicSuffixList

	// Notify is a channel on which the eTLDs+1 of all changed cookies
	// is annonced.
	// The caller must ensure that Notify has sufficient buffer space
	// to keep up with the expected change rate.
	Notify chan<- string

	// NotifyOn is the bitmap which determines which changes to the
	// jar will result in a notification message on the Notify channel.
	NotifyOn Notification
}

Options are the options for creating a new Jar.

Jump to

Keyboard shortcuts

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