Documentation
¶
Overview ¶
Package cookiejar はメモリ内で RFC 6265 に準拠した http.CookieJar を実装します。
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Jar ¶
type Jar struct {
// contains filtered or unexported fields
}
Jarはnet/httpパッケージのhttp.CookieJarインターフェースを実装しています。
func New ¶
Newは新しいクッキージャーを返します。nilの*OptionsはゼロのOptionsと同等です。
Example ¶
// クッキーを提供するためのサーバを開始する。 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if cookie, err := r.Cookie("Flavor"); err != nil { http.SetCookie(w, &http.Cookie{Name: "Flavor", Value: "Chocolate Chip"}) } else { cookie.Value = "Oatmeal Raisin" http.SetCookie(w, cookie) } })) defer ts.Close() u, err := url.Parse(ts.URL) if err != nil { log.Fatal(err) } // cookiejarのすべてのユーザーは、"golang.org/x/net/publicsuffix"をインポートする必要があります。 jar, err := cookiejar.New(&cookiejar.Options{PublicSuffixList: publicsuffix.List}) if err != nil { log.Fatal(err) } client := &http.Client{ Jar: jar, } if _, err = client.Get(u.String()); err != nil { log.Fatal(err) } fmt.Println("After 1st request:") for _, cookie := range jar.Cookies(u) { fmt.Printf(" %s: %s\n", cookie.Name, cookie.Value) } if _, err = client.Get(u.String()); err != nil { log.Fatal(err) } fmt.Println("After 2nd request:") for _, cookie := range jar.Cookies(u) { fmt.Printf(" %s: %s\n", cookie.Name, cookie.Value) }
Output: After 1st request: Flavor: Chocolate Chip After 2nd request: Flavor: Oatmeal Raisin
type Options ¶
type Options struct { // PublicSuffixListは、ドメインに対してHTTPサーバがクッキーを設定できるかどうかを決定する公開サフィックスリストです。 // // nilの値は有効であり、テストには便利ですが、セキュリティ上の理由から使用するべきではありません。これは、foo.co.ukのHTTPサーバがbar.co.ukに対してクッキーを設定できることを意味します。 PublicSuffixList PublicSuffixList }
Options は新しい Jar の作成オプションです。
type PublicSuffixList ¶
type PublicSuffixList interface { // PublicSuffix returns the public suffix of domain. // // TODO: specify which of the caller and callee is responsible for IP // addresses, for leading and trailing dots, for case sensitivity, and // for IDN/Punycode. PublicSuffix(domain string) string // String returns a description of the source of this public suffix // list. The description will typically contain something like a time // stamp or version number. String() string }
PublicSuffixListはドメインの公開サフィックスを提供します。例えば:
- "example.com"の公開サフィックスは「com」です。
- "foo1.foo2.foo3.co.uk"の公開サフィックスは「co.uk」です。
- "bar.pvt.k12.ma.us"の公開サフィックスは「pvt.k12.ma.us」です。
PublicSuffixListの実装は、複数のゴルーチンに対して安全に同時に使用できる必要があります。
常に""を返す実装は有効であり、テストには便利ですが、安全ではありません。これは、foo.comのHTTPサーバがbar.comのためにクッキーを設定できることを意味します。
golang.org/x/net/publicsuffixパッケージには、公開サフィックスリストの実装があります。
Click to show internal directories.
Click to hide internal directories.