[httpcomments-client-4.5.2]--源碼分析( HTTP entity)

來源:互聯網
上載者:User

HTTP messages can carry a content entity associated with the request or response. Entities can be found in some requests and in some responses, as they are optional. Requests that use entities are referred to as entity enclosing requests. The HTTP specification defines two entity enclosing request methods: POST and PUT. Responses are usually expected to enclose a content entity. There are exceptions to this rule such as responses to HEAD method and 204 No Content, 304 Not Modified, 205 Reset Content responses.

HttpClient distinguishes three kinds of entities, depending on where their content originates:
streamed: The content is received from a stream, or generated on the fly. In particular, this category includes entities being received from HTTP responses. Streamed entities are generally not repeatable.

self-contained: The content is in memory or obtained by means that are independent from a connection or other entity. Self-contained entities are generally repeatable. This type of entities will be mostly used for entity enclosing HTTP requests.
wrapping: The content is obtained from another entity.

This distinction is important for connection management when streaming out content from an HTTP response. For request entities that are created by an application and only sent using HttpClient, the difference between streamed and self-contained is of little importance. In that case, it is suggested to consider non-repeatable entities as streamed, and those that are repeatable as self-contained.

HTTP訊息可以攜帶一個請求和響應的內容關聯實體。實體可以在一些請求和一些響應中找到,因為它們是可選的。使用實體的請求被稱為實體封閉請求。HTTP規範定義了兩種實體封裝要求方法:POST和PUT。響應通常預計將包含一個內容實體。有此規則的異常,如回應標頭方法和204沒有內容,304沒有修改,205複位內容響應。

根據其內容來源於哪裡: HttpClient區分三種實體,

流:內容是從流接收,或動態產生的。特別是,這一類包括實體接收從HTTP響應。流實體一般不可重複。

包含:該內容是在記憶體中,或通過與串連或其他實體獨立的方式獲得的。包含的實體通常是可重複的。這種類型的實體將主要用於實體封裝HTTP請求。
封裝:內容是從另一個實體獲得的。
這種區別對於串連管理時流出來的內容從一個HTTP響應是很重要的。這是由一個應用只發送使用HttpClient請求實體流和獨立之間的差異並不重要。在這種情況下,建議考慮非可重複的實體作為流,和那些是可重複的作為獨立的。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.