最近阅读了cookie - rfc6265规范记录一下
cookie 官方名被称为HTTP State Management Mechanism, 其实官方文档也承认cookie并非只能用于http协议(Cookies do not provide isolation by scheme)。
谈到cookie 分为服务端和客户端。
1服务端需要在响应时设置cookie,通过Set-Cookie响应头对客户端进行cookie写入。
2客户端将携带cookie去发起请求,以下条件,cookie 将不会被携带
A.When cookies are disabled, the user agent MUST NOT include a Cookie header in outbound HTTP requests and the user agent MUST NOT process Set-Cookie headers in inbound HTTP responses. 大意就是cookie不可用时,不得携带cookie,不可用的条件:如过期,受同源策略影响不合适的cookie
cookie 的几个attribute介绍:
1The Expires Attribute 过期参数
2The Max-Age Attribute 值得一提 如果Max-Age 不合法,Expires将会被当作备用
3The Domain Attribute cookie-domain都是小写形式的
4The Path Attribute 每个路径可以有指定的cookie存储
5The Secure Attribute 安全参数如果设置 则只有安全通道能够获得cookie
6The HttpOnly Attribute 此参数如果被设置客户端不能通过脚本改变cookie