Request 请求
A request message from a client to a server includes, within the
first line of that message, the method to be applied to the resource,
the identifier of the resource, and the protocol version in use.
一个客户端向服务器的请求信息包括: 请求的方法,请求的内容,和请求所使用的协议.
Request = Request-Line ; Section 5.1
*(( general-header ; Section 4.5
| request-header ; Section 5.3
| entity-header ) CRLF) ; Section 7.1
CRLF
[ message-body ] ; Section 4.3
5.1 Request-Line 请求行
The Request-Line begins with a method token, followed by the
Request-URI and the protocol version, and ending with CRLF. The
elements are separated by SP characters. No CR or LF is allowed
except in the final CRLF sequence.
(CR carriage return 0x0D 回车, LF line feed 0x0A 换行, SP space 0x20 空格)
请求行是以请求方法开始, 后面是要请求的资源和HTTP协议的版本信息.
请求行的各部分以空格分开, 最后以回车换行结束请求行.
Request-Line = Method SP Request-URI SP HTTP-Version CRLF
请求行 = 请求方法 空格 要请求的资源 空格 HTTP的版本信息 回车换行
5.1.1 Method 请求的方法
The Method token indicates the method to be performed on the
resource identified by the Request-URI. The method is case-sensitive.
请求方式符号是大小写敏感的, 它指出了对URI所对应资源的处理方法..
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
extension-method = token
The list of methods allowed by a resource can be specified in an
Allow header field (section 14.7). The return code of the response
always notifies the client whether a method is currently allowed on a
resource, since the set of allowed methods can change dynamically. An
origin server SHOULD return the status code 405 (Method Not Allowed)
if the method is known by the origin server but not allowed for the
requested resource, and 501 (Not Implemented) if the method is
unrecognized or not implemented by the origin server. The methods GET
and HEAD MUST be supported by all general-purpose servers. All other
methods are OPTIONAL; however, if the above methods are implemented,
they MUST be implemented with the same semantics as those specified
in section 9.
资源可以通过Allow header field 指定它允许的请求方式, 可以通过请求的响应代码
来查看请求方式是否被允许, 资源所允许的各种请求方式是可以动态修改的.
如果请求方式可以被服务器识别但不被请求资源所允许 会返回405(方式不允许)
响应代码. 如果服务器无法识别这个请求方式或者无法执行这个请求方式就会返回
501(不可执行)响应代码.GET和HEAD请求方式是被所有的服务器所支持的., 其它的请求
方式都是可选的. 而且 同一个请求方式在不同的服务器上的语意(执行)要一致 ,
第九部分中有详细的说明..
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-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
General Header Fields
=============================
general header是request、response都可用的, 但是不能用于entity.
-- Cache-Control
-- Connection
-- Date
-- Pragma
-- Trailer
-- Transfer-Encoding
-- Upgrade
-- Via
-- Warning
*******************************************************************************
Request Header Fields
======================
request-header fields 允许客户端传递关于request和客户端的附加信息到服务端,
-- 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 Header Fields
===============================
response-header fields 允许服务端传递关于response的、不能放到Status-Line的附加信息。
这些头给出关于服务端的信息。
-- Accept-Ranges
-- Age
-- ETag
-- Location
-- Proxy-Authenticate
-- Retry-After
-- Server
-- Vary
-- WWW-Authenticate
*******************************************************************************
Entity Header Fields
========================
Entity-header fields 定义关于entity-body的metainformation(标题字段数据),
如果当前没有body, 则定义被request确定的资源信息.
一些metainformation是可选的; 一些是必须的。
-- Allow
-- Content-Encoding
-- Content-Language
-- Content-Length
-- Content-Location
-- Content-MD5
-- Content-Range
-- Content-Type
-- Expires
-- Last-Modified
-- extension-header