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

来源:互联网 发布:朝勇投资有限公司 知乎 编辑:程序博客网 时间:2024/05/16 15:20

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请求实体流和独立之间的差异并不重要。在这种情况下,建议考虑非可重复的实体作为流,和那些是可重复的作为独立的。

0 0
原创粉丝点击