gpt4 book ai didi

java - HTTP 1.1 流水线

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:46:27 37 4
gpt4 key购买 nike

我必须在 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/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com