Documentation
¶
Index ¶
- Constants
- Variables
- func CreateHostPrefixCookie(name, value string, maxAge int) *http.Cookie
- func CreatePartitionedCookie(name, value string, maxAge int) *http.Cookie
- func CreateSecureCookie(name, value string, maxAge int) *http.Cookie
- func CreateSecurePrefixCookie(name, value string, maxAge int) *http.Cookie
- func IsPartitioned(cookie *http.Cookie) bool
- func ParseCookieName(name string) (prefix int, originalName string)
- func SetCookie(w http.ResponseWriter, opts CookieOptions) error
- func ValidateCookieSecurity(cookie *http.Cookie) error
- type CookieOptions
Constants ¶
View Source
const ( PrefixNone = iota // 无前缀 PrefixSecure // __Secure- 前缀 PrefixHost // __Host- 前缀 )
前缀类型常量
View Source
const ( PartitionNone = iota // 不分区 PartitionPartitioned // 分区Cookie (Partitioned) )
分区类型常量
Variables ¶
View Source
var ( ErrInvalidCookieConfig = errors.New("无效的Cookie配置") ErrInsecureCookieConfig = errors.New("不安全的Cookie配置") )
错误定义
Functions ¶
func CreateHostPrefixCookie ¶
CreateHostPrefixCookie 创建使用__Host-前缀的Cookie
func CreatePartitionedCookie ¶
CreatePartitionedCookie 创建分区Cookie
func CreateSecureCookie ¶
CreateSecureCookie 创建安全Cookie
func CreateSecurePrefixCookie ¶
CreateSecurePrefixCookie 创建使用__Secure-前缀的Cookie
func ParseCookieName ¶
ParseCookieName 解析Cookie名,返回前缀类型和去除前缀的名称
func SetCookie ¶
func SetCookie(w http.ResponseWriter, opts CookieOptions) error
SetCookie 安全地设置Cookie
func ValidateCookieSecurity ¶
ValidateCookieSecurity 验证Cookie安全性
Types ¶
type CookieOptions ¶
type CookieOptions struct {
// 基本信息
Name string
Value string
Path string
Domain string
MaxAge int
Expires time.Time
Secure bool
HttpOnly bool
SameSite http.SameSite
// 增强特性
Prefix int // Cookie前缀类型 (PrefixNone, PrefixSecure, PrefixHost)
Partition bool // 是否为分区Cookie
}
CookieOptions 定义Cookie选项
func DefaultCookieOptions ¶
func DefaultCookieOptions() CookieOptions
DefaultCookieOptions 返回默认的安全Cookie选项
func (*CookieOptions) SecurityLevelString ¶
func (opts *CookieOptions) SecurityLevelString() string
SecurityLevelString 返回安全等级的描述
func (*CookieOptions) ToCookie ¶
func (opts *CookieOptions) ToCookie() (*http.Cookie, error)
ToCookie 将选项转换为http.Cookie
func (*CookieOptions) Validate ¶
func (opts *CookieOptions) Validate() error
Validate 验证Cookie选项是否有效
Click to show internal directories.
Click to hide internal directories.