HTTP响应头向客户端提供一些额外信息,比如谁在发送响应、响应者的功能,甚至与响应相关的一些特殊指令。这些头部有助于客户端处理响应,并在将来发起更好的请求。对响应头的操作是后端开发者的任务。
最基本且最常使用的就是允许跨域的头了。
Access-Control-Allow-Origin:配置有权限访问资源的域,* 表示允许所有域,常用的方式还有配置白名单,只允许个别域访问。
别的基本上都是按需自己加,也不经常用得到。
以下是所有的响应头,取自https://websec.readthedocs.io/zh/latest/network/http/http.html
- Accept-Ranges
- 表明服务器是否支持指定范围请求及哪种类型的分段请求
- Accept-Ranges: bytes
- Access-Control-Allow-Origin
- 配置有权限访问资源的域
- Access-Control-Allow-Origin: <origin>|*
- Age
- 从原始服务器到代理缓存形成的估算时间(以秒计,非负)
- Age: 12
- Allow
- 对某网络资源的有效的请求行为,不允许则返回405
- Allow: GET, HEAD
- Cache-Control
- 告诉所有的缓存机制是否可以缓存及哪种类型
- Cache-Control: no-cache
- Content-Encoding
- web服务器支持的返回内容压缩编码类型。
- Content-Encoding: gzip
- Content-Language
- 响应体的语言
- Content-Language: en,zh
- Content-Length
- 响应体的长度
- Content-Length: 348
- Content-Location
- 请求资源可替代的备用的另一地址
- Content-Location: /index.htm
- Content-MD5
- 返回资源的MD5校验值
- Content-MD5: Q2hlY2sgSW50ZWdyaXR5IQ==
- Content-Range
- 在整个返回体中本部分的字节位置
- Content-Range: bytes 21010-47021/47022
- Content-Type
- 返回内容的MIME类型
- Content-Type: text/html; charset=utf-8
- Date
- 原始服务器消息发出的时间
- Date: Tue, 15 Nov 2010 08:12:31 GMT
- ETag
- 请求变量的实体标签的当前值
- ETag: "737060cd8c284d8af7ad3082f209582d"
- Expires
- 响应过期的日期和时间
- Expires: Thu, 01 Dec 2010 16:00:00 GMT
- Last-Modified
- 请求资源的最后修改时间
- Last-Modified: Tue, 15 Nov 2010 12:45:26 GMT
- Location
- 用来重定向接收方到非请求URL的位置来完成请求或标识新的资源
- Location: http://www.zcmhi.com/archives/94.html
- Pragma
- 包括实现特定的指令,它可应用到响应链上的任何接收方
- Pragma: no-cache
- Proxy-Authenticate
- 它指出认证方案和可应用到代理的该URL上的参数
- Proxy-Authenticate: Basic
- Refresh
- 应用于重定向或一个新的资源被创造,在5秒之后重定向(由网景提出,被大部分浏览器支持)
- Refresh: 5; url=http://www.zcmhi.com/archives/94.html
- Retry-After
- 如果实体暂时不可取,通知客户端在指定时间之后再次尝试
- Retry-After: 120
- Server
- web服务器软件名称
- Server: Apache/1.3.27 (Unix) (Red-Hat/Linux)
- Set-Cookie
- 设置Http Cookie Set-Cookie: UserID=JohnDoe; Max-Age=3600; Version=1
- Strict-Transport-Security
- 设置浏览器强制使用HTTPS访问
- max-age: x秒的时间内 访问对应域名都使用HTTPS请求
- includeSubDomains: 网站的子域名也启用规则
- Strict-Transport-Security: max-age=1000; includeSubDomains
- Trailer
- 指出头域在分块传输编码的尾部存在 Trailer: Max-Forwards
- Transfer-Encoding
- 文件传输编码
- Transfer-Encoding:chunked
- Vary
- 告诉下游代理是使用缓存响应还是从原始服务器请求
- Vary: *
- Via
- 告知代理客户端响应是通过哪里发送的
- Via: 1.0 fred, 1.1 nowhere.com (Apache/1.1)
- Warning
- 警告实体可能存在的问题
- Warning: 199 Miscellaneous warning
- WWW-Authenticate
- 表明客户端请求实体应该使用的授权方案
- WWW-Authenticate: Basic
- X-Content-Type-Options
- 配置禁止MIME类型嗅探
- X-Content-Type-Options: nosniff
- X-Frame-Options
- 配置页面是否能出现在 <frame>, <iframe>, <embed>, <object> 等标签中,防止点击劫持
- X-Frame-Options: deny
- X-XSS-Protection
- 配置XSS防护机制
- X-XSS-Protection: 1; mode=block