cookiejar

Imports

Imports #

"cmp"
"errors"
"fmt"
"net"
"net/http"
"net/http/internal/ascii"
"net/url"
"slices"
"strings"
"sync"
"time"
"fmt"
"net/http/internal/ascii"
"strings"
"unicode/utf8"

Constants & Variables

acePrefix const #

acePrefix is the ASCII Compatible Encoding prefix.

const acePrefix = "xn--"

base const #

These parameter values are specified in section 5. All computation is done with int32s, so that overflow behavior is identical regardless of whether int is 32-bit or 64-bit.

const base int32 = 36

damp const #

These parameter values are specified in section 5. All computation is done with int32s, so that overflow behavior is identical regardless of whether int is 32-bit or 64-bit.

const damp int32 = 700

endOfTime var #

endOfTime is the time when session (non-persistent) cookies expire. This instant is representable in most date/time formats (not just Go's time.Time) and should be far enough in the future.

var endOfTime = *ast.CallExpr

errIllegalDomain var #

var errIllegalDomain = *ast.CallExpr

errMalformedDomain var #

var errMalformedDomain = *ast.CallExpr

initialBias const #

These parameter values are specified in section 5. All computation is done with int32s, so that overflow behavior is identical regardless of whether int is 32-bit or 64-bit.

const initialBias int32 = 72

initialN const #

These parameter values are specified in section 5. All computation is done with int32s, so that overflow behavior is identical regardless of whether int is 32-bit or 64-bit.

const initialN int32 = 128

skew const #

These parameter values are specified in section 5. All computation is done with int32s, so that overflow behavior is identical regardless of whether int is 32-bit or 64-bit.

const skew int32 = 38

tmax const #

These parameter values are specified in section 5. All computation is done with int32s, so that overflow behavior is identical regardless of whether int is 32-bit or 64-bit.

const tmax int32 = 26

tmin const #

These parameter values are specified in section 5. All computation is done with int32s, so that overflow behavior is identical regardless of whether int is 32-bit or 64-bit.

const tmin int32 = 1

Interfaces

PublicSuffixList interface #

PublicSuffixList provides the public suffix of a domain. For example: - the public suffix of "example.com" is "com", - the public suffix of "foo1.foo2.foo3.co.uk" is "co.uk", and - the public suffix of "bar.pvt.k12.ma.us" is "pvt.k12.ma.us". Implementations of PublicSuffixList must be safe for concurrent use by multiple goroutines. An implementation that always returns "" is valid and may be useful for testing but it is not secure: it means that the HTTP server for foo.com can set a cookie for bar.com. A public suffix list implementation is in the package golang.org/x/net/publicsuffix.

type PublicSuffixList interface {
PublicSuffix(domain string) string
String() string
}

Structs

Jar struct #

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

type Jar struct {
psList PublicSuffixList
mu sync.Mutex
entries map[string]map[string]entry
nextSeqNum uint64
}

Options struct #

Options are the options for creating a new Jar.

type Options struct {
PublicSuffixList PublicSuffixList
}

entry struct #

entry is the internal representation of a cookie. This struct type is not used outside of this package per se, but the exported fields are those of RFC 6265.

type entry struct {
Name string
Value string
Quoted bool
Domain string
Path string
SameSite string
Secure bool
HttpOnly bool
Persistent bool
HostOnly bool
Expires time.Time
Creation time.Time
LastAccess time.Time
seqNum uint64
}

Functions

Cookies method #

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 (j *Jar) Cookies(u *url.URL) (cookies []*http.Cookie)

New function #

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

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

SetCookies method #

SetCookies implements the SetCookies method of the [http.CookieJar] interface. It does nothing if the URL's scheme is not HTTP or HTTPS.

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

adapt function #

adapt is the bias adaptation function specified in section 6.1.

func adapt(delta int32, numPoints int32, firstTime bool) int32

canonicalHost function #

canonicalHost strips port from host if present and returns the canonicalized host name.

func canonicalHost(host string) (string, error)

cookies method #

cookies is like Cookies but takes the current time as a parameter.

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

defaultPath function #

defaultPath returns the directory part of a URL's path according to RFC 6265 section 5.1.4.

func defaultPath(path string) string

domainAndType method #

domainAndType determines the cookie's domain and hostOnly attribute.

func (j *Jar) domainAndType(host string, domain string) (string, bool, error)

domainMatch method #

domainMatch checks whether e's Domain allows sending e back to host. It differs from "domain-match" of RFC 6265 section 5.1.3 because we treat a cookie with an IP address in the Domain always as a host cookie.

func (e *entry) domainMatch(host string) bool

encode function #

encode encodes a string as specified in section 6.3 and prepends prefix to the result. The "while h < length(input)" line in the specification becomes "for remaining != 0" in the Go code, because len(s) in Go is in bytes, not runes.

func encode(prefix string, s string) (string, error)

encodeDigit function #

func encodeDigit(digit int32) byte

hasDotSuffix function #

hasDotSuffix reports whether s ends in "."+suffix.

func hasDotSuffix(s string, suffix string) bool

hasPort function #

hasPort reports whether host contains a port number. host may be a host name, an IPv4 or an IPv6 address.

func hasPort(host string) bool

id method #

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

func (e *entry) id() string

isIP function #

isIP reports whether host is an IP address.

func isIP(host string) bool

jarKey function #

jarKey returns the key to use for a jar.

func jarKey(host string, psl PublicSuffixList) string

newEntry method #

newEntry creates an entry from an http.Cookie c. now is the current time and is compared to c.Expires to determine deletion of c. defPath and host are the default-path and the canonical host name of the URL c was received from. remove records whether the jar should delete this cookie, as it has already expired with respect to now. In this case, e may be incomplete, but it will be valid to call e.id (which depends on e's Name, Domain and Path). A malformed c.Domain will result in an error.

func (j *Jar) newEntry(c *http.Cookie, now time.Time, defPath string, host string) (e entry, remove bool, err error)

pathMatch method #

pathMatch implements "path-match" according to RFC 6265 section 5.1.4.

func (e *entry) pathMatch(requestPath string) bool

setCookies method #

setCookies is like SetCookies but takes the current time as parameter.

func (j *Jar) setCookies(u *url.URL, cookies []*http.Cookie, now time.Time)

shouldSend method #

shouldSend determines whether e's cookie qualifies to be included in a request to host/path. It is the caller's responsibility to check if the cookie is expired.

func (e *entry) shouldSend(https bool, host string, path string) bool

toASCII function #

toASCII converts a domain or domain label to its ASCII form. For example, toASCII("bücher.example.com") is "xn--bcher-kva.example.com", and toASCII("golang") is "golang".

func toASCII(s string) (string, error)

Generated with Arrow