2. 架构
HTTP was created for the World Wide Web (WWW) architecture and has evolved over time to support the scalability needs of a worldwide hypertext system. Much of that architecture is reflected in the terminology and syntax productions used to define HTTP.
HTTP 是为万维网(WWW)架构创建的并且可以随时根据万维网超文本系统的拓展需要而进化。该架构大部分映射到定义 HTTP 的语法与术语生成。
2.1. 客户端/服务端消息
HTTP is a stateless request/response protocol that operates by exchanging messages (Section 3) across a reliable transport- or session-layer "connection" (Section 6). An HTTP "client" is a program that establishes a connection to a server for the purpose of sending one or more HTTP requests. An HTTP "server" is a program that accepts connections in order to service HTTP requests by sending HTTP responses.
HTTP 是无状态请求/响应协议,通过可靠的传输层或会话层 “连接” 交换消息。一个 HTTP “客户端” 是建立连接到服务端的程序,为某些目的发送一个或多个 HTTP 请求。一个 HTTP 服务器是接收连接的程序,为了服务 HTTP 请求而发送 HTTP 响应。
The terms "client" and "server" refer only to the roles that these programs perform for a particular connection. The same program might act as a client on some connections and a server on others. The term "user agent" refers to any of the various client programs that initiate a request, including (but not limited to) browsers, spiders (web-based robots), command-line tools, custom applications, and mobile apps. The term "origin server" refers to the program that can originate authoritative responses for a given target resource. The terms "sender" and "recipient" refer to any implementation that sends or receives a given message, respectively.
术语 “客户端” 和 “服务端” 专指这些执行特定连接的程序。同样的程序也许在某些连接作为客户端或者在其它连接作为服务端。“user agent” 指客户端程序发起请求,包括(但不限于)浏览器,蜘蛛爬虫(基于 web robots 协议),命令行工具,自定义应用程序,和手机应用。术语 “origin server” 指可以对给定目标资源进行来源授权响应的程序。术语 “sender” 和 “recipient” 分别指发送或接收给定消息的实现。
HTTP relies upon the Uniform Resource Identifier (URI) standard [RFC3986] to indicate the target resource (Section 5.1) and relationships between resources. Messages are passed in a format similar to that used by Internet mail [RFC5322] and the Multipurpose Internet Mail Extensions (MIME) [RFC2045] (see Appendix A of [RFC7231] for the differences between HTTP and MIME messages).
HTTP 依赖统一资源标识符(URL)标准 RFC3986 标识目标资源(章节 5.1)和资源之间的关系。消息传递使用的格式是被 Internet mail 和 Multipurpose Internet Mail Extensions (MIME)使用的类似格式(见 RFC7231 的附录 A 比较 HTTP 和 MIME 消息之间的差异)。
Most HTTP communication consists of a retrieval request (GET) for a representation of some resource identified by a URI. In the simplest case, this might be accomplished via a single bidirectional connection (===) between the user agent (UA) and the origin server (O).
大部分 HTTP 通信由请求(GET)检索一些以 URL 标识的资源的表现组成。最简单的例子,它可以通过源服务器(O)和用户代理(UA)之间的单个双向传输连接(===)完成。
request >
UA ======================================= O
< response
A client sends an HTTP request to a server in the form of a request message, beginning with a request-line that includes a method, URI, and protocol version (Section 3.1.1), followed by header fields containing request modifiers, client information, and representation metadata (Section 3.2), an empty line to indicate the end of the header section, and finally a message body containing the payload body (if any, Section 3.3).
客户端以请求消息的形式向服务端发送 HTTP 请求,request 行开头包含 method,URL,和协议版本(章节 3.1.1),接着的 header 字段包含 请求变动信息,客户端信息,和表现元数据(章节 3.2),一个空行表示 header 章节结束,最后的消息主体包含在 payload body(如果有,章节 3.3)。
A server responds to a client's request by sending one or more HTTP response messages, each beginning with a status line that includes the protocol version, a success or error code, and textual reason phrase (Section 3.1.2), possibly followed by header fields containing server information, resource metadata, and representation metadata (Section 3.2), an empty line to indicate the end of the header section, and finally a message body containing the payload body (if any, Section 3.3).
服务端通过发送一个或多个 HTTP 响应消息响应客户端的请求,每一个消息以状态行开头,包含协议版本,成功或失败代码,和文本原因短语(章节 3.1.2)。可能会跟着 header 字段,包含服务器信息,资源元数据,和表现元数据(章节 3.2),一个空行表示 header 章节结束,最后的消息主体包含在 payoad body (如果有,章节 3.3)。
A connection might be used for multiple request/response exchanges, as defined in Section 6.3.
一个连接可能被用在多个请求/响应交换,在章 6.3 定义。
The following example illustrates a typical message exchange for a GET request (Section 4.3.1 of [RFC7231]) on the URI "http://www.example.com/hello.txt":
下面的例子演示一个典型的 GET 请求数据交换(RFC7231的章节 4.3)在 URL "http://www.example.com/hello.txt"。
Client request:
GET /hello.txt HTTP/1.1
User-Agent: curl/7.16.3 libcurl/7.16.3 OpenSSL/0.9.7l zlib/1.2.3
Host: www.example.com
Accept-Language: en, mi
Server response:
HTTP/1.1 200 OK
Date: Mon, 27 Jul 2009 12:28:53 GMT
Server: Apache
Last-Modified: Wed, 22 Jul 2009 19:15:56 GMT
ETag: "34aa387-d-1568eb00"
Accept-Ranges: bytes
Content-Length: 51
Vary: Accept-Encoding
Content-Type: text/plain
Hello World! My payload includes a trailing CRLF.
网友评论