HTTP1.0-1.1差异

HTTP1.1-1.0差别

备注:本文主要基于HTTP1.1规范的角度进行两个版本的对比。

Protocol Parameters

Date/Time Formats

(接收方向)

无论是HTTP1.0还是HTTP1.1,都要能解析下面三种date/time stamp:

Sun, 06 Nov 1994 08:49:37 GMT  ; RFC 822, updated by RFC 1123

Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036

Sun Nov  6 08:49:37 1994       ; ANSI C's asctime() format

(发送方向)

HTTP1.0要求不能生成第三种asctime格式的date/time stamp;

HTTP1.1则要求只生成RFC 1123(第一种)格式的date/time stamp。

Content Codings

HTTP1.1支持:

gzip、compress、deflate(zlib格式)

HTTP1.0支持:

gzip、compress

Transfer Codings

HTTP1.1:

支持chunked transfer,所以可以有Transfer-Encoding头部域:

Transfer-Encoding: chunked

备注:(详见rfc2616-3.6.1)

chunked 编码修饰消息的主体,为了以一系列的大块传输它,每块都有它自己的大小指示符,接在【可选】的包含实体头部域的尾巴后。这允许动态生成的内容与必要信息一起传输,以便接收者检验它已经接收完全部的消息。

Quality Values

HTTP1.1:

HTTP 内容协商(12 节)使用简短的“浮点”数来指出各种协商参数的相对重要性(“权重”。权重通常是 0 到 1 范围内的实数,这里 0 是最小的,1 是最大的。如果某个参数的质) 量值为 0,则该参数对于该客户来说“不可接受”。

Entity Tags

HTTP1.1:

实体标签用来从相同的请求资源来比较两个或多个实体。HTTP/1.1在ETag、If-Match、If-None-Match和If-Range头部域中使用实体 标签。这几个标签在HTTP in Cache中使用。

Range Units

HTTP1.1:

允许客户端只请求响应实体的某部分包含在响应中。HTTP/1.1 在 Range 和Content-Range头部域中使用范围单位。实体可以依据各种结构

化单位分割为子范围。

bytes-unit = "bytes"

other-range-unit = token

HTTP/1.1 定义的唯一范围单位是“bytes”。

HTTP Message

General Header Fields

红色为HTTP1.1新增:

general-header = Cache-Control ; Section 14.9

                      | Connection               ; Section 14.10
                      | Date                     ; Section 14.18
                      | Pragma                   ; Section 14.32
                      | Trailer                  ; Section 14.40
                      | Transfer-Encoding        ; Section 14.41
                      | Upgrade                  ; Section 14.42
                      | Via                      ; Section 14.45
                      | Warning                  ; Section 14.46

Request

Method

红色为HTTP1.1新增:

Method         = "OPTIONS"                ; Section 9.2
                      | "GET"                    ; Section 9.3
                      | "HEAD"                   ; Section 9.4
                      | "POST"                   ; Section 9.5
                      | "PUT"                    ; Section 9.6
                      | "DELETE"                 ; Section 9.7
                      | "TRACE"                  ; Section 9.8
                      | "CONNECT"                ; Section 9.9
                      | extension-method

Request Header Fields

红色为HTTP1.1新增:

 request-header = Accept                   ; Section 14.1
                      | Accept-Charset           ; Section 14.2
                      | Accept-Encoding          ; Section 14.3
                      | Accept-Language          ; Section 14.4
                      | Authorization            ; Section 14.8
                      | Expect                   ; Section 14.20
                      | From                     ; Section 14.22
                      | Host                     ; Section 14.23
                      | If-Match                 ; Section 14.24
                      | If-Modified-Since        ; Section 14.25
                      | If-None-Match            ; Section 14.26
                      | If-Range                 ; Section 14.27
                      | If-Unmodified-Since      ; Section 14.28
                      | Max-Forwards             ; Section 14.31
                      | Proxy-Authorization      ; Section 14.34
                      | Range                    ; Section 14.35
                      | Referer                  ; Section 14.36
                      | TE                       ; Section 14.39
                      | User-Agent               ; Section 14.43

Response

Status Code

红色为HTTP1.1新增:

Status-Code    =
            "100"  ; Section 10.1.1: Continue
          | "101"  ; Section 10.1.2: Switching Protocols
          | "200"  ; Section 10.2.1: OK
          | "201"  ; Section 10.2.2: Created
          | "202"  ; Section 10.2.3: Accepted
          | "203"  ; Section 10.2.4: Non-Authoritative Information
          | "204"  ; Section 10.2.5: No Content
          | "205"  ; Section 10.2.6: Reset Content
          | "206"  ; Section 10.2.7: Partial Content
          | "300"  ; Section 10.3.1: Multiple Choices
          | "301"  ; Section 10.3.2: Moved Permanently
          | "302"  ; Section 10.3.3: Found(与HTTP1.0中的302意义不一样)
          | "303"  ; Section 10.3.4: See Other
          | "304"  ; Section 10.3.5: Not Modified
          | "305"  ; Section 10.3.6: Use Proxy
          | "307"  ; Section 10.3.8: Temporary Redirect
          | "400"  ; Section 10.4.1: Bad Request
          | "401"  ; Section 10.4.2: Unauthorized
          | "402"  ; Section 10.4.3: Payment Required
          | "403"  ; Section 10.4.4: Forbidden
          | "404"  ; Section 10.4.5: Not Found
          | "405"  ; Section 10.4.6: Method Not Allowed
          | "406"  ; Section 10.4.7: Not Acceptable
          | "407"  ; Section 10.4.8: Proxy Authentication Required
          | "408"  ; Section 10.4.9: Request Time-out
          | "409"  ; Section 10.4.10: Conflict
          | "410"  ; Section 10.4.11: Gone
          | "411"  ; Section 10.4.12: Length Required
          | "412"  ; Section 10.4.13: Precondition Failed
          | "413"  ; Section 10.4.14: Request Entity Too Large
          | "414"  ; Section 10.4.15: Request-URI Too Large
          | "415"  ; Section 10.4.16: Unsupported Media Type
          | "416"  ; Section 10.4.17: Requested range not satisfiable
          | "417"  ; Section 10.4.18: Expectation Failed
          | "500"  ; Section 10.5.1: Internal Server Error
          | "501"  ; Section 10.5.2: Not Implemented
          | "502"  ; Section 10.5.3: Bad Gateway
          | "503"  ; Section 10.5.4: Service Unavailable
          | "504"  ; Section 10.5.5: Gateway Time-out
          | "505"  ; Section 10.5.6: HTTP Version not supported
          | extension-code

Response Header Fields

红色为HTTP1.1新增:

response-header = Accept-Ranges           ; Section 14.5
                       | Age                     ; Section 14.6
                       | ETag                    ; Section 14.19
                       | Location                ; Section 14.30
                       | Proxy-Authenticate      ; Section 14.33
                       | Retry-After             ; Section 14.37
                       | Server                  ; Section 14.38
                       | Vary                    ; Section 14.44
                       | WWW-Authenticate        ; Section 14.47

Entity

Entity Header Fields

红色为HTTP1.1新增:

entity-header  = Allow                    ; Section 14.7
                      | Content-Encoding         ; Section 14.11
                      | Content-Language         ; Section 14.12
                      | Content-Length           ; Section 14.13
                      | Content-Location         ; Section 14.14
                      | Content-MD5              ; Section 14.15
                      | Content-Range            ; Section 14.16
                      | Content-Type             ; Section 14.17
                      | Expires                  ; Section 14.21
                      | Last-Modified            ; Section 14.29
                      | extension-header

Connection

Persistent connection

HTTP1.1:

支持persistent connection,并且默认使用

HTTP1.0:

支持persistent connection需要显性增加Connection: Keep-Alive header,默认不使用

Pipelining

HTTP1.1:

支持永久连接的客户端<可以>按“管道”方式请求(如,发送多个请求而不需等待每个响应)。服务器<必须>必须以收到请求的相同顺序来响应发送这些请求的响应。

Caching in HTTP

HTTP1.1:

完整的cache管理机制,引入Expiration Model、Validation Model模型

HTTP1.0:

只包括几种cache处理机制:no-cache\If-Modified-Since\Last-Modified\Expires,只是通过简单的计算时间进行处理

备注:详细情况参见参考文献【2】。

总结

从对比HTTP1.1和1.0的情况看有如下几个需要注意的特性:

业务相关

  • Range机制

该机制提供基于range的请求,如果我们的CDN后续需要引入视频等业务时,则在我们的CDN系统中必须支持该特性。

功能相关

  • Cache机制

HTTP1.1的Cache机制远比1.0复杂和高效,在我们的Cache系统中主要注意兼容性问题。

  • Chunk编码机制

Chunk编码机制在需要输出动态内容时可以有效的提高用户体验,让用户及时的得到部分数据。

性能相关

  • Persistent Connection

  • Pipeline

参考文献

【1】rfc2616 http://www.ietf.org/rfc/rfc2616.txt

【2】rfc1945 http://www.ietf.org/rfc/rfc1945.txt

作者: cbin_07   发布时间: 2010-09-21