Documentation
¶
Overview ¶
cookiejar 包实现了内存中符合 RFC 6265 的 http.CookieJar。
这个实现是 net/http/cookiejar 的一个分支,它也 实现将 cookie 转储到持久化的方法 存储和检索它们。
Index ¶
- func DefaultCookieFile() string
- type Jar
- func (j *Jar) AllCookies() (cookies []*http.Cookie)
- func (j *Jar) Cookies(u *url.URL) (cookies []*http.Cookie)
- func (j *Jar) LoadJSON(str string) error
- func (j *Jar) MarshalJSON() ([]byte, error)
- func (j *Jar) RemoveAll()
- func (j *Jar) RemoveAllHost(host string)
- func (j *Jar) RemoveCookie(c *http.Cookie)
- func (j *Jar) Save() error
- func (j *Jar) SetCookies(u *url.URL, cookies []*http.Cookie)
- func (j *Jar) ToJSON() string
- type Options
- type PublicSuffixList
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultCookieFile ¶
func DefaultCookieFile() string
DefaultCookieFile 返回要使用的默认 cookie 文件 用于持久化 cookie 数据。 以下名称将按优先级降序使用: -$GOCOOKIES 环境变量的值。 -$HOME/.go-cookies
Types ¶
type Jar ¶
type Jar struct {
// contains filtered or unexported fields
}
Jar 实现了 net/http 包中的 http.CookieJar 接口。
func New ¶
New 返回一个新的 cookie jar。 nil *Options 相当于零 选项。
如果 cookie 无法加载,New 将返回错误 出于任何原因从文件中读取,而不是文件不存在。
func (*Jar) AllCookies ¶
AllCookies 返回 jar 中的所有 cookie。返回的cookie将 填写了 Domain、Expires、HttpOnly、Name、Secure、Path 和 Value 出去。过期的 cookie 将不会被退回。该功能不 修改cookie jar。
func (*Jar) Cookies ¶
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) MarshalJSON ¶
MarshalJSON 通过编码所有持久性 cookie 来实现 json.Marshaler 当前在罐子中。
func (*Jar) RemoveAllHost ¶
RemoveAllHost 从 jar 中删除为给定主机设置的所有 cookie。
func (*Jar) RemoveCookie ¶
RemoveCookie 删除与名称、域和路径匹配的cookie 由 c 指定。
func (*Jar) Save ¶
Save saves the cookies to the persistent cookie file. Before the file is written, it reads any cookies that have been stored from it and merges them into j.
func (*Jar) SetCookies ¶
SetCookies 实现了 http.CookieJar 接口的 SetCookies 方法。
如果 URL 的方案不是 HTTP 或 HTTPS,则不会执行任何操作。
type Options ¶
type Options struct { //PublicSuffixList为公共后缀列表,判断是否 //HTTP 服务器可以为域设置 cookie。 // //如果为 nil,则为 golang.org/x/net/publicsuffix 中的公共后缀列表实现 //被使用。 PublicSuffixList PublicSuffixList //Filename 保存用于存储 cookie 的文件。 //如果为空,则使用 DefaultCookieFile 的值。 Filename string //NoPersist 指定是否不应该使用持久性 //(对于测试有用)。如果这是真的,文件名的值将是 //被忽略。 NoPersist bool }
Options 是创建新 Jar 的选项。
type PublicSuffixList ¶
type PublicSuffixList interface { //PublicSuffix 返回域的公共后缀。 // //TODO: 指定调用者和被调用者中的哪一个负责 IP //地址,前导点和尾随点,区分大小写,以及 //对于 IDN/Punycode。 PublicSuffix(domain string) string //String 返回此公共后缀来源的描述 //列表。描述通常会包含诸如时间之类的内容 //标记或版本号。 String() string }
PublicSuffixList 提供域的公共后缀。例如: -“example.com”的公共后缀是“com”, -“foo1.foo2.foo3.co.uk”的公共后缀是“co.uk”,并且 -“bar.pvt.k12.ma.us”的公共后缀是“pvt.k12.ma.us”。
PublicSuffixList 的实现必须对于并发使用是安全的 多个 goroutine。
始终返回“”的实现是有效的并且可能对 测试但不安全:这意味着 foo.com 的 HTTP 服务器可以 为 bar.com 设置 cookie。
包中包含公共后缀列表实现 golang.org/x/net/publicsuffix。