# package cookiejar
`import "net/http/cookiejar"`
cookiejar包实现了保管在内存中的符合[RFC 6265标准的](http://tools.ietf.org/html/rfc6265)http.CookieJar接口。
## Index
* [type PublicSuffixList](#PublicSuffixList)
* [type Options](#Options)
* [type Jar](#Jar)
* [func New(o \*Options) (\*Jar, error)](#New)
* [func (j \*Jar) Cookies(u \*url.URL) (cookies []\*http.Cookie)](#Jar.Cookies)
* [func (j \*Jar) SetCookies(u \*url.URL, cookies []\*http.Cookie)](#Jar.SetCookies)
## type [PublicSuffixList](http://code.google.com/p/go/source/browse/src/pkg/net/http/cookiejar/jar.go?name=release#34 "View Source")
```
type PublicSuffixList interface {
// 返回域名的公共后缀。
// TODO:域名的格式化应该由调用者还是接口方法负责还没有确定。
PublicSuffix(domain 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接口的实现必须是并发安全的。一个总是返回""的实现是合法的,也可以通过测试;但却是不安全的:它允许HTTP服务端跨域名设置cookie。推荐实现:[code.google.com/p/go.net/publicsuffix](http://godoc.org/code.google.com/p/go.net/publicsuffix)
## type [Options](http://code.google.com/p/go/source/browse/src/pkg/net/http/cookiejar/jar.go?name=release#49 "View Source")
```
type Options struct {
// PublicSuffixList是公共后缀列表,用于决定HTTP服务端是否能给某域名设置cookie
// nil值合法的,也可以通过测试;但却是不安全的:它允许HTTP服务端跨域名设置cookie
PublicSuffixList PublicSuffixList
}
```
Options是创建新Jar是的选项。
## type [Jar](http://code.google.com/p/go/source/browse/src/pkg/net/http/cookiejar/jar.go?name=release#60 "View Source")
```
type Jar struct {
// 内含隐藏或非导出字段
}
```
Jar类型实现了net/http包的http.CookieJar接口。
### func [New](http://code.google.com/p/go/source/browse/src/pkg/net/http/cookiejar/jar.go?name=release#77 "View Source")
```
func New(o *Options) (*Jar, error)
```
返回一个新的Jar,nil指针等价于Options零值的指针。
### func (\*Jar) [Cookies](http://code.google.com/p/go/source/browse/src/pkg/net/http/cookiejar/jar.go?name=release#171 "View Source")
```
func (j *Jar) Cookies(u *url.URL) (cookies []*http.Cookie)
```
实现CookieJar接口的Cookies方法,如果URL协议不是HTTP/HTTPS会返回空切片。
### func (\*Jar) [SetCookies](http://code.google.com/p/go/source/browse/src/pkg/net/http/cookiejar/jar.go?name=release#235 "View Source")
```
func (j *Jar) SetCookies(u *url.URL, cookies []*http.Cookie)
```
实现CookieJar接口的SetCookies方法,如果URL协议不是HTTP/HTTPS则不会有实际操作。
- 库
- package achive
- package tar
- package zip
- package bufio
- package builtin
- package bytes
- package compress
- package bzip2
- package flate
- package gzip
- package lzw
- package zlib
- package container
- package heap
- package list
- package ring
- package crypto
- package aes
- package cipher
- package des
- package dsa
- package ecdsa
- package elliptic
- package hmac
- package md5
- package rand
- package rc4
- package rsa
- package sha1
- package sha256
- package sha512
- package subtle
- package tls
- package x509
- package pkix
- package database
- package sql
- package driver
- package encoding
- package ascii85
- package asn1
- package base32
- package base64
- package binary
- package csv
- package gob
- package hex
- package json
- package pem
- package xml
- package errors
- package expvar
- package flag
- package fmt
- package go
- package doc
- package format
- package parser
- package printer
- package hash
- package adler32
- package crc32
- package crc64
- package fnv
- package html
- package template
- package image
- package color
- package palette
- package draw
- package gif
- package jpeg
- package png
- package index
- package suffixarray
- package io
- package ioutil
- package log
- package syslog
- package math
- package big
- package cmplx
- package rand
- package mime
- package multipart
- package net
- package http
- package cgi
- package cookiejar
- package fcgi
- package httptest
- package httputil
- package pprof
- package mail
- package rpc
- package jsonrpc
- package smtp
- package textproto
- package url
- package os
- package exec
- package signal
- package user
- package path
- package filepath
- package reflect
- package regexp
- package runtime
- package cgo
- package debug
- package pprof
- package race
- package sort
- package strconv
- package strings
- package sync
- package atomic
- package text
- package scanner
- package tabwriter
- package template
- package time
- package unicode
- package utf16
- package utf8
- package unsafe