2. 架構(gòu)
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 是為萬維網(wǎng)(WWW)架構(gòu)創(chuàng)建的并且可以隨時(shí)根據(jù)萬維網(wǎng)超文本系統(tǒng)的拓展需要而進(jìn)化。該架構(gòu)大部分映射到定義 HTTP 的語法與術(shù)語生成。
2.1. 客戶端/服務(wù)端消息
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 是無狀態(tài)請(qǐng)求/響應(yīng)協(xié)議,通過可靠的傳輸層或會(huì)話層 “連接” 交換消息。一個(gè) HTTP “客戶端” 是建立連接到服務(wù)端的程序,為某些目的發(fā)送一個(gè)或多個(gè) HTTP 請(qǐng)求。一個(gè) HTTP 服務(wù)器是接收連接的程序,為了服務(wù) HTTP 請(qǐng)求而發(fā)送 HTTP 響應(yīng)。
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.
術(shù)語 “客戶端” 和 “服務(wù)端” 專指這些執(zhí)行特定連接的程序。同樣的程序也許在某些連接作為客戶端或者在其它連接作為服務(wù)端。“user agent” 指客戶端程序發(fā)起請(qǐng)求,包括(但不限于)瀏覽器,蜘蛛爬蟲(基于 web robots 協(xié)議),命令行工具,自定義應(yīng)用程序,和手機(jī)應(yīng)用。術(shù)語 “origin server” 指可以對(duì)給定目標(biāo)資源進(jìn)行來源授權(quán)響應(yīng)的程序。術(shù)語 “sender” 和 “recipient” 分別指發(fā)送或接收給定消息的實(shí)現(xiàn)。
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 依賴統(tǒng)一資源標(biāo)識(shí)符(URL)標(biāo)準(zhǔn) RFC3986 標(biāo)識(shí)目標(biāo)資源(章節(jié) 5.1)和資源之間的關(guān)系。消息傳遞使用的格式是被 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 通信由請(qǐng)求(GET)檢索一些以 URL 標(biāo)識(shí)的資源的表現(xiàn)組成。最簡單的例子,它可以通過源服務(wù)器(O)和用戶代理(UA)之間的單個(gè)雙向傳輸連接(===)完成。
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).
客戶端以請(qǐng)求消息的形式向服務(wù)端發(fā)送 HTTP 請(qǐng)求,request 行開頭包含 method,URL,和協(xié)議版本(章節(jié) 3.1.1),接著的 header 字段包含 請(qǐng)求變動(dòng)信息,客戶端信息,和表現(xiàn)元數(shù)據(jù)(章節(jié) 3.2),一個(gè)空行表示 header 章節(jié)結(jié)束,最后的消息主體包含在 payload body(如果有,章節(jié) 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).
服務(wù)端通過發(fā)送一個(gè)或多個(gè) HTTP 響應(yīng)消息響應(yīng)客戶端的請(qǐng)求,每一個(gè)消息以狀態(tài)行開頭,包含協(xié)議版本,成功或失敗代碼,和文本原因短語(章節(jié) 3.1.2)。可能會(huì)跟著 header 字段,包含服務(wù)器信息,資源元數(shù)據(jù),和表現(xiàn)元數(shù)據(jù)(章節(jié) 3.2),一個(gè)空行表示 header 章節(jié)結(jié)束,最后的消息主體包含在 payoad body (如果有,章節(jié) 3.3)。
A connection might be used for multiple request/response exchanges, as defined in Section 6.3.
一個(gè)連接可能被用在多個(gè)請(qǐng)求/響應(yīng)交換,在章 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":
下面的例子演示一個(gè)典型的 GET 請(qǐng)求數(shù)據(jù)交換(RFC7231的章節(jié) 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.