HTTP/1.1协议规范(中文归纳版)
一、介绍(introduction)
-
目的——HTTP/0.9-〉HTTP/1.0-〉HTTP/1.1
-
要求——MUST、REQUIRED、SHOULD
-
术语——连接(Connection)、消息(Message)、请求(Request)、应答(Response)、资源(Resource)、实体 (Entity)、表示方法(Representation)、内容协商(Content Negotiation)、变量(Variant)、客户机(Client)、用户代理(User agent)、服务器(Server)、原服务器(Origin server)、代理服务器( Proxy)、网关(gateway)、高速缓存(Cache)、可缓存(Cacheable)、直接(first-hand)、明确终止时间 (explicit expiration time)、探索终止时间(heuristic expiration time)、年龄(Age)、保鲜寿命(Freshness lifetime)、保鲜(Fresh)、陈旧(Stale)、语义透明(semantically transparent)、有效性判别器(Validator)、实体标记(entity tag)或最终更改时间(Last-Modified time))、上游/下游(upstream/downstream)、向内/向外(inbound/outbound)
-
总体操作——请求/应答、中介
二、符号惯例与一般语法(notational conversions and generic grammar)
-
扩充BNF——name = definition,"literal",rule1 | rule2,(rule1 rule2),*rule,,N rule, #rule,; comment, implied *LWS
-
基本规则——OCTET,CHAR,UPALPHA,LOALPHA,ALPHA,DIGIT,CTL,CR,LF,SP,HT,<">
三、协议参数(protocol parameters)
-
HTTP版本——HTTP-Version = "HTTP" "/" 1DIGIT "." 1DIGIT
-
统一资源标示符(URI)——统一资源定位器(URL)和统一资源名称(URN)的结合,http_URL = "http:" "//" host ]
-
日期/时间格式——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
-
字符集——本文档中的术语"字符集"指一种用一个或更多表格将一个八字节序列转换成一个字符序列的方法, charset=token 失踪字符集
-
内容编码——内容编码主要用来允许文档压缩(信源编码) content-coding= token 注册表包含下列标记:gzip,compress,deflate,identity
-
传输编码——目的是能够确保通过网络安全传输(信道编码) transfer-coding = "chunked" | transfer-extension transfer-extension = token *( ";" parameter ), 成块传输代码
-
媒体类型——media-type = type "/" subtype *( ";" parameter ) type = token subtype = token 规范化和原文缺省 多部分类型
-
产品标记——product = token product-version = token
-
质量值——qvalue = ( "0" )| ( "1" )
-
语言标记——language-tag = primary-tag ( "-" subtag ) primary-tag = 18ALPHA subtag = 1*8ALPHA
-
实体标记——entity-tag = opaque-tag weak = "W/" opaque-tag = quoted-string
-
范围单位——range-unit = bytes-unit | other-range-unit bytes-unit = "bytes" other-range-unit = token
四、 HTTP消息(HTTP message)
-
消息类型——HTTP-message = Request | Response ; HTTP/1.1 messages generic-message = start-line *(message-header CRLF) CRLF start-line = Request-Line | Status-Line
-
消息头——HTTP头域包括常规头,请求头,应答头和实体头域 message-header = field-name ":" field-name = token field-value = *( field-content | LWS ) field-content = <the OCTETs making up the field-value and consisting of either *TEXT or combinations of token, separators, and quoted-string>
-
消息体——message-body = entity-body|
-
消息的长度——决定因素
-
常规头域——general-header = Cache-Control| Connection| Date| Pragma| Transfer-Encoding
五、 请求(request)
首行包括利用资源的方式,区分资源的标识,以及协议的版本号 Request = Request-Line * (( general-header| request-header| entity-header ) CRLF) CRLF
-
请求行——Request-Line = Method SP Request-URI SP HTTP-Version CRLF 方法——方法标记指的是在请求URI所指定的资源上所实现的方式 Method = "OPTIONS"| "GET"| "POST"| "PUT"| "DELETE"| "TRACE"| "CONNECT"| extension-method extension-method = token 请求URL——请求URL是一种全球统一的应用于资源请求的资源标识符 Request-URI = "*" | absoluteURI | abs_path | authority 请求行举例:GET http://www.w3.org/pub/WWW/TheProject.html HTTP/1.1 GET /pub/WWW/TheProject.html HTTP/1.1 Host: www.w3.org
-
请求定义的资源——一个INTERNET请求所定义的精确资源由请求URL和主机报头域所决定
-
请求报头域——request-header = Accept| Accept-Charset| Accept-Encoding| Accept-Language| Authorization| Expect| From| Host| If-Match| If-Modified-Since| If-None-Match| If-Range| If-Unmodified-Since| Max-Forwards| Proxy-Authorization| Range| Referer| TE| User-Agent
六、 应答(response)
接收和翻译一个请求信息后,服务器发出一个HTTP应答信息 Response = Status-Line*(( general-header| response-header| entity-header ) CRLF) CRLF
-
状态行——Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF 状态码——状态码是试图理解和满足请求的三位数字的整数码,1xx,2xx,3xx,4xx,5xx,100-〉505-〉扩展码
-
应答报头域——response-header = Accept-Ranges| Age| Location| Proxy-Authenticate| Retry-After| Server| Vary| WWW-Authenticate
七、 实体(entity)
在未经特别规定的情况下,请求与应答的消息也可以传送实体。 实体包括实体报头域与实体正文,而有些应答只包括实体报头。
-
实体报头域——entity-header = Allow | Content-Encoding| Content-Language| Content-Length | Content-Location| Content-MD5| Content-Range| Content-Type| Expires| Last-Modified| extension-header extension-header = message-header
-
实体正文——entity-body = *OCTET entity-body := Content-Encoding( Content-Type( data ) )
八、 连接(connection)
-
持续连接——优点 持续连接是任何HTTP连接的缺省方式,支持持续连接的客户机可以以流水线方式发送请求 代理服务器
-
消息传递要求——持续连接与流量控制 监视连接中出错状态的消息 100号状态的用途 服务器过早关闭连接时客户机的动作
九、 方法定义(method definitions)
-
安全和等幂方法 安全方法——GET和HEAD方法除了补救外不应该有别的采取措施的含义 等幂方法——没有副作用的序列是等幂的
-
OPTIONS——OPTIONS方法代表在请求URI确定的请求/应答过程中通信条件是否可行的信息
-
GET——GET方法说明了重建信息的内容由请求URI来确定
-
HEAD——除了应答中禁止返回消息正文外,HEAD方法与GET方法一样
-
POST——POST方法实现的实际功能取决于服务器
-
PUT——PUT方法要求所附实体存储在提供的请求URI下
-
DELETE——DELELE方法要求原服务器释放请求URI指向的资源
-
TRACE——TRACE方法用于调用远程的应用层循环请求消息
-
CONNECT——CONNECT方法用于能动态建立起隧道的代理服务器
十、 状态码定义(status code definitions)
-
信息1XX—— 100继续 101转换协议
-
成功2XX—— 200请求成功 201创建 202接受 203非权威信息 204无内容 205重置内容 206局部内容
-
重新定向3XX—— 300多样选择 301永久移动 302创立 303观察别的部分 304只读 306(没有用的) 307临时重发
-
客户错误4xx—— 400坏请求 401未授权的 402必需的支付 403禁用 404没有找到 405不被允许的方法 406不接受 407代理服务器认证所必需 408请求超时 409冲突 410停止 411必需的长度 412预处理失败 413请求实体太大 414请求的URI过长 415不被支持的媒体类型 416请求范围不满足 417期望失败
-
服务器错误5xx—— 500服务器内部错误 501不能实现 502坏网关 503难以获得的服务 504网关超时 505 HTTP版本不支持
十一、 访问验证(access authentication)——可选择
十二、 内容谈判(content negotiation)
HTTP为了"内容谈判"提供了一些机制,即当有很多种可能的表示时如何选择对于一个请求的最佳的表示。
-
服务器驱动谈判——一个请求的最佳表示的选择由服务器提供的运算法则来完成
-
代理驱动谈判——对于一个应答的最佳表示法的选择是在代理从原服务器端收到最初的应答后实现的
-
透明谈判——透明的判断是服务器驱动和代理驱动谈判的结合体
十三、 HTTP中的缓存(caching in HTTP)
HTTP典型应用于能通过采用缓存技术而提高性能的分布式信息系统
-
缓存—— 缓存正确性 警告信息 缓存控制机制 直接的用户代理警告 规则和警告的例外情况 由客户控制的行为
-
过期模型—— 服务器指定模型 启发式过期 年龄计算 过期计算 澄清过期值 澄清多重响应
-
确认模型——当缓存器想要用一个失时效的条目来相应客户的请求,他首先必须向源服务器检验这一缓存条目是否仍然可用 最后修改日期 标签缓存确认器 强弱控制器 关于何时使用实体标签和最后修改时间的规则 不确认条件
-
响应的缓存能力——除非被明确限制,缓存系统可以将一成功的响应作为缓存实体一直存储
-
从缓存构造响应—— 端到端和Hop-by-hop报头 不可更改报头 联合报头 联合字节范围
-
缓存谈判响应
-
共享与非共享缓存
-
错误和不完全响应缓存行为
-
GET和 HEAD的副作用
-
刷新或删除后的无效性
-
强制写通过
-
缓存替换
-
历史纪录
十四、 报头域定义(header field definitions)
-
Accept——Accept = "Accept" ":" #( media-range ) media-range = ( "/"| ( type "/" "*" )| ( type "/" subtype )) *( ";" parameter ) accept-params = ";" "q" "=" qvalue ( accept-extension ) accept-extension = ";" token 例1:Accept: audio/; q=0.2, audio/basic 例2:Accept: text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c
-
Accept-Charset——Accept-Charset = "Accept-Charset" ":" 1#( ( charset | "*" ) ) 例:Accept-Charset: iso-8859-5, unicode-1-1;q=0.8
-
Accept-Encoding——Accept-Encoding = "Accept-Encoding" ":" 1#( codings ) codings = ( content-coding | "*" ) 例:Accept-Encoding: gzip;q=1.0, identity; q=0.5, *;q=0
-
Accept-Language——Accept-Language = "Accept-Language" ":" 1#( language-range ) language-range = ( ( 18ALPHA ( "-" 18ALPHA ) ) | "" ) 例:Accept-Language: da, en-gb;q=0.8, en;q=0.7
-
Accept-Range——Accept-Ranges = "Accept-Ranges" ":" acceptable-ranges acceptable-ranges = 1#range-unit | "none" 例:Accept-Ranges: bytes
-
Age——Age = "Age" ":" age-value age-value = delta-seconds
-
Allow——Allow = "Allow" ":" #Method 例:Allow: GET, HEAD, PUT
-
Authorization——Authorization = "Authorization" ":" credentials
-
Cache-Control——Cache-Control = "Cache-Control" ":" 1#cache-directive cache-directive = cache-request-directive| cache-response-directive cache-request-directive ="no-cache"| "no-store"| "max-age" "=" delta-seconds| "max-stale" | "min-fresh" "=" delta-seconds| "no-transform"| "only-if-cached"| cache-extension cache-response-directive ="public"| "private" | "no-cache" | "no-store"| "no-transform"| "must-revalidate"| "proxy-revalidate"| "max-age" "=" delta-seconds| "s-maxage" "=" delta-seconds| cache-extension cache-extension = token 什么是可缓存的 哪些可能被缓存保存 对基本过期失效机制的改进 缓存重新确认有效和重载控制 不得转换的指令 缓存控制扩展
-
Connection——Connection = "Connection" ":" 1#(connection-token) connection-token = token 例:Connection: close
-
Content-Encoding——Content-Encoding = "Content-Encoding" ":" 1#content-coding 例:Content-Encoding: gzip
-
Content-Language——Content-Language = "Content-Language" ":" 1#language-tag 例:Content-Language: mi, en
-
Content-Length——Content-Length = "Content-Length" ":" 1*DIGIT Content-Length: 3495
-
Content-Location——Content-Location = "Content-Location" ":"( absoluteURI | relativeURI )
-
Content-MD5——Content-MD5 = "Content-MD5" ":" md5-digest md5-digest = <base64 of 128 bit MD5 digest as per RFC 1864>
-
Content-Range——Content-Range = "Content-Range" ":" content-range-spec content-range-spec = byte-content-range-spec byte-content-range-spec = bytes-unit SP byte-range-resp-spec "/"( instance-length | "" ) byte-range-resp-spec = (first-byte-pos "-" last-byte-pos) | "" instance-length = 1*DIGIT 例:The first 500 bytes:bytes 0-499/1234
-
Content-Type——Content-Type = "Content-Type" ":" media-type 例:Content-Type: text/html; charset=ISO-8859-4
-
Date——Date = "Date" ":" HTTP-date 例:Date: Tue, 15 Nov 1994 08:12:31 GMT 没有时钟的原服务器的运作
-
Etag——ETag = "ETag" ":" entity-tag 例:ETag: W/"xyzzy"
-
Expect——Expect = "Expect" ":" 1#expectation expectation = "100-continue" | expectation-extension expectation-extension = token expect-params = ";" token
-
Expires——Expires = "Expires" ":" HTTP-date 例:Expires: Thu, 01 Dec 1994 16:00:00 GMT
-
From——From = "From" ":" mailbox 例:From: webmaster@w3.org
-
Host——Host = "Host" ":" host ; Section 3.2.2
-
If-Match——If-Match = "If-Match" ":" ( "*" | 1#entity-tag ) 例:If-Match: "xyzzy", "r2d2xxxx", "c3piozzzz"
-
If-Modified-Since——If-Modified-Since = "If-Modified-Since" ":" HTTP-date 例:If-Modified-Since: Sat, 29 Oct 1994 19:43:31 GMT
-
If-None-Match ——If-None-Match = "If-None-Match" ":" ( "*" | 1#entity-tag ) 例:If-None-Match: W/"xyzzy", W/"r2d2xxxx", W/"c3piozzzz"
-
If-Range ——If-Range = "If-Range" ":" ( entity-tag | HTTP-date )
-
If-Unmodified-Since ——If-Unmodified-Since = "If-Unmodified-Since" ":" HTTP-date 例:If-Unmodified-Since: Sat, 29 Oct 1994 19:43:31 GMT
-
Last-Modified ——Last-Modified = "Last-Modified" ":" HTTP-date 例:Last-Modified: Tue, 15 Nov 1994 12:45:26 GMT
-
Location ——Location = "Location" ":" absoluteURI Location: http://www.w3.org/pub/WWW/People.html
-
Max-Forwards ——Max-Forwards = "Max-Forwards" ":" 1*DIGIT
-
Pragma ——Pragma = "Pragma" ":" 1#pragma-directive pragma-directive = "no-cache" | extension-pragma extension-pragma = token
-
Proxy-Authenticate ——Proxy-Authenticate = "Proxy-Authenticate" ":" 1#challenge
-
Proxy-Authorization ——Proxy-Authorization = "Proxy-Authorization" ":" credentials
-
Range——字节范围 范围检索请求 Range = "Range" ":" ranges-specifier
-
Referer——Referer = "Referer" ":" ( absoluteURI | relativeURI )
-
Retry-After ——Retry-After = "Retry-After" ":" ( HTTP-date | delta-seconds )
-
Server ——Server = "Server" ":" 1*( product | comment )
-
TE ——TE = "TE" ":" #( t-codings ) t-codings = "trailers" | ( transfer-extension ) 例:TE: trailers, deflate;q=0.5
-
Trailer ——Trailer = "Trailer" ":" 1#field-name
-
Transfer-Encoding ——Transfer-Encoding = "Transfer-Encoding" ":" 1#transfer-coding 例:Transfer-Encoding: chunked
-
Upgrade——Upgrade = "Upgrade" ":" 1#product 例:Upgrade: HTTP/2.0, SHTTP/1.3, IRC/6.9, RTA/x11
-
User-Agent ——User-Agent = "User-Agent" ":" 1*( product | comment ) 例:User-Agent: CERN-LineMode/2.15 libwww/2.17b3
-
Vary ——Vary = "Vary" ":" ( "*" | 1#field-name )
-
Via ——Via = "Via" ":" 1#( received-protocol received-by ) received-protocol = protocol-version protocol-name = token protocol-version = token received-by = ( host ) | pseudonym pseudonym = token 例:Via: 1.0 ricky, 1.1 ethel, 1.1 fred, 1.0 lucy
-
Warning = "Warning" ":" 1#warning-value warning-value = warn-code SP warn-agent SP warn-text warn-code = 3DIGIT warn-agent = ( host ) | pseudonym warn-text = quoted-string warn-date = <"> HTTP-date <">
-
WWW-Authenticate ——WWW-Authenticate = "WWW-Authenticate" ":" 1#challenge
十五、 安全考虑(security considerations)
一些建议,但是并不包括最终解决方案
-
个人信息 服务器日志信息的滥用 敏感信息的传输 URI中敏感信息的编码 连接到Accept报头的机要问题
-
基于文件和路径名称的攻击
-
DNS欺骗
-
Location(位置)报头和欺骗
-
内容倾向问题
-
鉴定证书和空闲的客户机
-
代理服务器和高速缓存 对代理服务器的拒绝服务攻击
十六、 感谢
十七、 参考文献
十八、 作者地址
十九、 附录
文章转自:http://www.cppblog.com/woaidongmao/archive/2008/05/28/51408.html
:) 瞄瞄。。。