HTTP/1.1:消息語法與路由 - 2.1 客戶端/服務(wù)端消息

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.
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 229,836評(píng)論 6 540
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 99,275評(píng)論 3 428
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 177,904評(píng)論 0 383
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經(jīng)常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 63,633評(píng)論 1 317
  • 正文 為了忘掉前任,我火速辦了婚禮,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 72,368評(píng)論 6 410
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 55,736評(píng)論 1 328
  • 那天,我揣著相機(jī)與錄音,去河邊找鬼。 笑死,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,740評(píng)論 3 446
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 42,919評(píng)論 0 289
  • 序言:老撾萬榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 49,481評(píng)論 1 335
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 41,235評(píng)論 3 358
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 43,427評(píng)論 1 374
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 38,968評(píng)論 5 363
  • 正文 年R本政府宣布,位于F島的核電站,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 44,656評(píng)論 3 348
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 35,055評(píng)論 0 28
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 36,348評(píng)論 1 294
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 52,160評(píng)論 3 398
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 48,380評(píng)論 2 379

推薦閱讀更多精彩內(nèi)容