;
用法
- 通过Set-Cookie设置
 - 下次请求会自动带上
 - 键值对,可以设置多个
 
属性
- max-age和expires设置过期时间
 - Secure只在https的时候发送
 - HttpOnly无法通过document.cookie访问
 
示例1:服务端Set-Cookie
1  | <!-- index.html -->  | 
1  | const http = require('http');  | 
;
;
示例2:max-age属性
我们修改server.js中Set-Cookie的内容,加上max-age属性
1  | res.writeHead(200, {  | 
;
两秒后再刷新页面
;
示例3: HttpOnly属性
我们修改server.js中Set-Cookie的内容,加上HttpOnly属性
1  | res.writeHead(200, {  | 
;
;