java - HTTP 1.1 流水线

标签 java http rfc2616 pipelining

我必须在 Java 中实现一个 HTTP 客户端,对于我的需要来说,最有效的方法似乎是实现 HTTP 管道(根据 RFC2616)。

顺便说一句,我想对 POST 进行流水线处理。 (此外,我不是在谈论多路复用。我在谈论流水线,即在接收任何响应之前通过一个连接发送许多请求 - HTTP 请求的批处理)

我找不到明确声明它支持流水线的第三方库。但我可以使用例如Apache HTTPCore构建这样的客户端,或者如果必须,我自己构建它。

我的问题是这是否是个好主意。我还没有找到任何权威的引用资料表明 HTTP 流水线不仅仅是一个理论模型,而且是由 HTTP 服务器正确实现的。此外,所有支持流水线的浏览器都默认关闭此功能。

所以,我应该尝试实现这样的客户端,否则我会因为服务器的实现(或代理)而遇到很多麻烦。是否有任何引用资料可以提供这些指导方针?

如果这是一个坏主意,那么提高效率的替代编程模型是什么?单独的 TCP 连接?

最佳答案

POST 不应流水线化

8.1.2.2 Pipelining

A client that supports persistent connections MAY "pipeline" its requests (i.e., send multiple requests without waiting for each response). A server MUST send its responses to those requests in the same order that the requests were received.

Clients which assume persistent connections and pipeline immediately after connection establishment SHOULD be prepared to retry their connection if the first pipelined attempt fails. If a client does such a retry, it MUST NOT pipeline before it knows the connection is persistent. Clients MUST also be prepared to resend their requests if the server closes the connection before sending all of the corresponding responses.

Clients SHOULD NOT pipeline requests using non-idempotent methods or non-idempotent sequences of methods (see section 9.1.2). Otherwise, a premature termination of the transport connection could lead to indeterminate results. A client wishing to send a non-idempotent request SHOULD wait to send that request until it has received the response status for the previous request.

http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html

关于java - HTTP 1.1 流水线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3298257/

相关文章:

java - 变量在打印出来之前不会更新?

java - 在实现该接口(interface)的类中引用接口(interface)常量的最佳实践是什么?

java - Spring Mail生成空指针异常

java没有这样的方法(java.lang.NoSuchMethodException)异常

javascript - 以编程方式提交执行 JS 的表单

ruby - 如何通过 ruby​​ 脚本从 Web 服务器请求 gzip 压缩页面?

Git代理绕过

ios - 使用AFNetworking的AFHTTPRequestOperation读取状态行(状态代码和原因短语)

http - rfc2616 中的 "1#"是什么

http - Flask:使用数组参数实现 HTTP GET