1 Request:

method: GET, HEAD, POST.(...)

  • Get --- Retrive Data.
  • Head --- The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response. (只有head,没有body)
  • Post --- 上交数据。

head:

小组1:

  • Accept --- certain media types which are acceptable for the response.
  • Accept-Charset --- indicate what character sets are acceptable for the response.
  • Accept-Encoding --- restricts the content-codings that are acceptable in the response
  • Accept-Language --- restricts the set of natural languages that are preferred as a response to the request.

小组1中的accept这类代表:user agent 希望接收的类型。
小组1例:

  • Accept: */* ---- 可以接收任何类型。
  • Accept-Language: zh-cn,zh;q=0.5 ---- 最希望接收中国的中文,如果没有接收其他国家的zh也可以,但对于我来说质量就只能为q=0.5了。
  • Accept-Encoding: gzip,deflate ---- 可以接收的传输内容压缩方式为gzip deflate
  • Accept-Charset: GB2312,utf-8;q=0.7,*;q=0.7 ----- 最希望接收的编码为GB2312,如果没有GB2312的版本的话,可以传送utf-8的,再没有就传送其他的也可以。不过GB2312默认q=1,utf-8对我来说就只剩q=0.7了。

小组2:

  • Host --- the Internet host and port number of the resource being requested
  • Referer --- allows the client to specify, for the server's benefit, the address (URI) of the resource from which the Request-URI was obtained
  • User-Agent --- contains information about the user agent originating the request

小组2中代表的是一些主机信息,和User-Agent的一些信息。
小组2例,假设我在我的windows上的火狐浏览器中使用hao123上的链接去访问google的话,request里面上述几个head field的信息是这样的:

  • Host: www.google.com.hk
  • User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13
  • Referer: http://www.hao123.com/

小组3:

  • If-*, 是一些跟cache control的validate有关的head,放到下面和response里有关cache control有关的head一起说。

小组4:

一些不常用到的request head:

  • Authorization
  • From
  • Max-Forwards
  • Proxy-Authorization
  • Range
  • TE
  • Expect --- 比如加上 100-continue,The purpose of the 100 (Continue) status (see section 10.1.1) is to allow a client that is sending a request messagewith a request body to determine if the origin server is willing to accept the request (based on the request headers)before the client sends the request body.(只有当Server传回一个100-continue的reponse之后,再继续传输body,否则就不在传输body了)

2 Response

Status Code:

There are 5 values for the first digit:

  • 1xx: Informational - Request received, continuing process
  • 2xx: Success - The action was successfully received, understood, and accepted
  • 3xx: Redirection - Further action must be taken in order to complete the request
  • 4xx: Client Error - The request contains bad syntax or cannot be fulfilled
  • 5xx: Server Error - The server failed to fulfill an apparently valid request

head:

小组1:

  • Accept-Ranges
  • ETag
  • Location
  • Proxy-Authenticate
  • Retry-After
  • Server  --- contains information about the software used by the origin server to handle the request
  • WWW-Authenticate

小组1中其他的,说实话,不是特别常用。

小组2:

  • Age
  • Vary

也用于Cache Control,后面一起讲。

3 Entity

head:

小组1:

  • Content-Encoding --- used as a modifier to the compressed enconding type
  • Content-Language --- describes the natural language(s) of the intended audience for the enclosed entity.
  • Content-Length --- indicates the size of the entity-body, in decimal number of OCTETs, sent to the recipient
  • Content-Location --- defines the base URI for the entity
  • Content-MD5 --- an MD5 digest of the entity-body for the purpose of providing an end-to-end message integrity check (MIC) of the entity-body
  • Content-Range --- 不常用,可先不看
  • Content-Type --- indicates the media type of the entity-body sent to the recipient

小组1提供的是发送的entity的属性,当从client使用POST method发送数据给server时候,需要包含content属性。从server给client response的时候,也需要包含content属性。下面为一例:

  • Content-Type          text/html; charset=UTF-8
  • Content-Encoding    gzip
  • Content-Length       7176

小组2:

  • Expires
  • Last-Modified

这两项也是用于Cache Control,会在下面Cache中一起说。

4 Cache Control

为了提高性能,才多出来这么多的head field用于cache control。

Goal:
The goal of caching in HTTP/1.1 is to eliminate the need to send requests in many cases, and to eliminate the need to send full responses in many other cases. The former reduces the number of network round-trips required for many operations; we use an “expiration”mechanism for this purpose (see section 13.2). The latter reduces network bandwidth requirements; we use a
validation” mechanism for this purpose (see section 13.3).

expiration:

HTTP caching works best when caches can entirely avoid making requests to the origin server. The primary
mechanism for avoiding requests is for an origin server to provide an explicit expiration time in the future, indicating that a response MAY be used to satisfy subsequent requests. In other words, a cache can return a fresh response without first contacting the server.

这里跟expire关联到的head field如下:

小组1:

  • Date --- the date and time at which the message was originated, having the same semantics as orig-date
  • Age --- the sender's/cache's estimate of the amount of time since the response (or its revalidation) was generated at the origin server.

小组1(均在response中出现)的用于计算当前的response的实际的age,因为只有real-age不超过response的fresh-lifetime,这个response才有效。
实际的计算公式是:corrected_received_age = max(now - date_value, age_value).

小组2:

  • Expires --- The Expires entity-header field gives the date/time after which the response is considered stale.
  • Cache-Control -- specify directives that MUST be obeyed by all caching mechanisms along the request/response chain.These directives typically override the default caching algorithms.

小组2中的Expires和Cache-Control的max-age directive用于计算fresh-lifetime.

  • The max-age directive takes priority over Expires, so if max-age is present in a response, the calculation is simply:  freshness_lifetime = max_age_value
  • Otherwise, if Expires is present in the response, the calculation is:
    freshness_lifetime = expires_value - date_value

例子:

  • Expires: Fri, 05 Oct 2012 00:00:00 GMT
  • Date: Fri, 07 Oct 2011 22:38:05 GMT
  • Cache-Control: public, max-age=31536000
  • Age: 190190

计算出来后,如果age < freshness_lifetime,那么这个response is fresh, or it should be validated!

Validation

When a cache has a stale entry that it would like to use as a response to a client’s request, it first has to check with the origin server to see if its cached entry is still usable. We call this “validating” the cache entry. Since we do not want to have to pay the overhead of retransmitting the full response if the cached entry is good, and we do not want to pay the overhead of an extra round trip if the cached entry is invalid, the HTTP/1.1 protocol supports the use of conditional methods.

小组1:

When an origin server generates a full response, it attaches some sort of validator to it, which is kept with the cache entry.
response中的一些validator:

  • Last-Modified --- 最后修改的时间。 In simple terms, a cache entry is considered to be valid if the entity has not been modified since the Last-Modified value.
  • ETag -- 不常用。虽然内容很多,不提了这里。

小组2:

A conditional request looks exactly the same as a normal request for the same resource, except that it
carries a special header (which includes the validator) that implicitly turns the method (usually, GET) into a
conditional。

在request中的一些validator:

  • If-Modified-Since or If-Unmodified-Since -- 如果response过期的话,就non-fresh response进行validate, 根据response传过来的Last-Modified.
  • If-Match, If-None-Match, or If-Range  --- 使用ETag进行校验的手法,暂时用不到。

转载于:https://www.cnblogs.com/jack204/archive/2011/10/09/2204118.html

Http协议head和cache control使用分类小结相关推荐

  1. 【Manual】Memory Cache Control

    [Intel-64 and IA-32 Architectures Software Developer's Manual]Chapter 11 本章节关于 memory cache.cache co ...

  2. cache-control_网站 cache control 最佳实践

    有时,当第二次访问网站时,看起来比较怪,样式不正常. 通常,是因为 cache control 缓存控制策略定义不正确,导致服务端最新部署之后客户端没有接收到最新的更改. 本文将向您展示正确的缓存设置 ...

  3. 基于SMB协议的共享文件读写 博客分类: Java

    基于SMB协议的共享文件读写 博客分类: Java 一.SMB协议 SMB协议是基于TCP-NETBIOS下的,一般端口使用为139,445. 服务器信息块(SMB)协议是一种IBM协议,用于在计算机 ...

  4. 协议 类似_IPv6基础及地址分类,地址发现协议,一分钟了解下

    一.IPv6地址分类 1.单播地址 特殊地址: ::1/128:环回地址,114 个 0,类似于 IPv4 的 127.0.0.1. ::/128:未指定地址,128 个 0,类似于 IPv4 的 0 ...

  5. 协议簇: Media Access Control(MAC) Frame 解析

    Media Access Control(MAC) Frame 解析 前言 千里之行,始于足下. 因为个人从事网络协议开发,一直想深入的学习一下协议族,从这篇开始,我将开始记录分享我学习到的网络协议相 ...

  6. html cache control 设置,关于 浏览器 Cache-Control 不能设置问题。

    首先,缓存问题依靠html的meta标签解决是不靠谱的,一般大型网站都依靠nginx server在 http头中对静态资源设置缓存. 而影响缓存的http头有好几个,尽管http 1.1协议之后,从 ...

  7. 【计算机网络】网络层 : ICMP 协议 ( ICMP 差错报文 | 差错报文分类 | ICMP 询问报文 | ICMP 应用 | Ping | Traceroute )

    文章目录 一.ICMP 协议 二.ICMP 协议 简介 三.ICMP 五种差错报告报文 四.ICMP 差错报文形成 五.ICMP 差错报文 不发送 情形 六.ICMP 询问报文 七.ICMP 应用 一 ...

  8. HTTP 头部字段 Cache Control max-age = 0 和 no-cache 的区别

    禁掉缓存的情况:请求百度首页 开启缓存的情况下: 似乎没有什么变化. 再观察请求的头部字段:cache-control: max-age=0 标头 Cache-Control: max-age=0 暗 ...

  9. 通信协议/通讯协议 有哪些?包含哪些分类?

    通讯和通信的区别? 1  "通信"与"通讯"傻傻分得清 传统意义上的"通讯"主要指电话.电报.电传.通讯的"讯"指消息( ...

最新文章

  1. 爬虫之requests模块发送带参数的请求
  2. mysql学习-常用的函数(字符串函数)
  3. jsp文件通常用common_29.jsp-动态生活之用Commons-FileUpload组件控制文件上传
  4. scala简明教程:偏函数、高阶函数、Future异步编程、隐式转换
  5. LeetCode 第 28 场双周赛(505/2144,前23.6%)
  6. 求最小连续和(洛谷P1614题题解,Java语言描述)
  7. nginx忽略文件名大小写
  8. 客户端脚本selectivizr,PIE,Respond.js
  9. java玻璃效果_swing透明效果(没aero毛玻璃那么好看)
  10. 2003服务器系统QQ安装不了,windows2003server
  11. 双线性函数matlab,双线性插值(Matlab实现)
  12. 机器学习7-逻辑斯蒂回归实现西瓜数据集2.0的二分类
  13. ant design入门_Umi + ant Design Pro最简单的入门教程(一)初
  14. pc机安装android,4种在PC机上运行Android系统的方法
  15. 【世界杯赛程表】v1.3 100614 我做的M8软件!
  16. Promise对象的基础入门学习
  17. Word无法打开该文件,因为文件格式与文件扩展名不匹配的解决方法
  18. MultipartFile.transferTo(dest) 报找不到文件错误以及解决方法
  19. vue移动端项目微信公众号授权登录
  20. 为什么需要职场软实力

热门文章

  1. Hdu 4604 DP
  2. 物联网卡开启消费市场新模式!
  3. 新托福写作:因果推论法
  4. jstree设置不可选中
  5. html语言添加下划线,HTML页面中怎么文本添加下划线?
  6. 【百家争鸣】反思O2O模式:为何没有飞天的猪
  7. 使用SimpleITK读取、保存、处理nii文件
  8. alex -颜值打分系统
  9. 含分布式能源电网储能容量优化 双层优化模型
  10. 《利用python进行数据分析》ch02