《图解http》读书笔记 - HTTP首部

1 通用首部字段

通用首部字段指,请求报文和响应报文双方都使用的首部。

1.1 Cache-Control

Cache-Control 能够控制缓存的行为。

缓存请求指令

指令 参数 说明
no-cache 强制向源服务器再次验证
no-store 不缓存请求或响应的任何内容
max-age = [ 秒] 必需 响应的最大Age值
max-stale( = [ 秒]) 可省略 接收已过期的响应
min-fresh = [ 秒] 必需 期望在指定时间内的响应仍有效
no-transform 代理不可更改媒体类型
only-if-cached 从缓存获取资源
cache-extension - 新指令标记(token)

缓存响应指令

指令 参数 说明
public 可向任意方提供响应的缓存
private 可省略 仅向特定用户返回响应
no-cache 可省略 缓存前必须先确认其有效性
no-store 不缓存请求或响应的任何内容
no-transform 代理不可更改媒体类型
must-revalidate 可缓存但必须再向源服务器进行确认
proxy-revalidate 要求中间缓存服务器对缓存的响应有效性再进行确认
max-age = [ 秒] 必需 响应的最大Age值
s-maxage = [ 秒] 必需 公共缓存服务器响应的最大Age值
cache-extension - 新指令标记(token)

1.1.1 public 指令

Cache-Control: public

使用public指令的时候表示,任何人都可以使用缓存。

1.1.2 private 指令

Cache-Control: private

只会给特定的用户提供资源缓存的服务,其他用户请求的时候不会返回缓存。

1.1.3 no-cache 指令

Cache-Control: no-cache

使用no-cache指令的目的是,为了防止从缓存返回过期的资源。
请求首部包含no-cache 指,表示客户端不接受缓存过的响应。于是,缓存服务器必须把客户端请求转发给源服务器。
响应首部包含no-cache 指,缓存服务器

1.1.4 no-store 指令

Cache-Control: no-store

该指令规定缓存不能在本地存储请求或响应的任一部分

1.1.5 max-age 指令
Cache-Control: max-age=604800(单位:秒)

  • 客户端指令中包含max-age指令的时候,判断缓存资源没有超过指定时间的情况下,客户端接受缓存资源。
  • 当客户端的max-age指令值0的时候,通常是缓存服务器转发客户端请求给源服务器。
  • 服务器端返回的响应中包含max-age指令的时候,缓存服务器不在对资源有效性进行确认。max-age代表资源保存缓存的最长时间。

1.1.6 s-maxage 指令
Cache-Control: s-maxage=604800(单位 :秒)

  • s-maxage指令跟max-age指令功能相同。
  • 他们的不同点是S-maxage指令指适用于共多为用户使用的公共缓存服务器。
  • 当使用 s-maxage 指令后,则直接忽略对 Expires 首部字段及max-age 指令的处理。

1.1.7 min-fresh指令
Cache-Control: min-fresh=60(单位:秒)

rfc2616定义:Indicates that the client is willing to accept a response whose freshness lifetime is no less than its current age plus the specified time in seconds. That is, the client wants a response that will still be fresh for at least the specified number of seconds.
大概是说:客户端希望接受缓存的有效期大于当前时间加上min-fresh指定的时间。如翻译有误请各位看官指正。

1.1.8 max-stale 指令
Cache-Control: max-stale=3600(单位:秒)

rfc2616定义: Indicates that the client is willing to accept a response that has exceeded its expiration time. If max-stale is assigned a value,then the client is willing to accept a response that has exceeded its expiration time by no more than the specified number of seconds. If no value is assigned to max-stale, then the client is willing to accept a stale response of any age.
max-stale没有指定参数的情况下,缓存无论过期多久都会接收。如果指定了参数,只要处于max-state指定的时间之内都接收。

1.1.9 only-if-cached指令
1.1.10 must-revalidate 指令
1.1.11 proxy-revalidate 指令
1.1.12 no-transform 指令
1.1.13 Cache-Control 扩展

1.2 Connection

1.3 Date

1.4 Pragma

1.5 Trailer

1.6 Transfer-Encoding

1.7 Upgrade

1.8 Via

1.9 Warning

2 请求首部字段

你可能感兴趣的:(软件测试)