想知道是否有人可以在管线化的上下文中,提供关于HTTP 1.1是半双工还是全双工的令人信服的解释?据我所知,在客户端收到响应之前,可以通过相同的持久连接发送多个请求。那么这是否意味着服务器可以对先前的请求进行响应,同时客户端发送新请求?
想知道是否有人可以在管线化的上下文中,提供关于HTTP 1.1是半双工还是全双工的令人信服的解释?据我所知,在客户端收到响应之前,可以通过相同的持久连接发送多个请求。那么这是否意味着服务器可以对先前的请求进行响应,同时客户端发送新请求?
HTTP是一种请求-响应协议。客户端发送请求,服务器等待完整的请求接收后再发送响应。客户端和服务器不能同时发送。
全双工通道意味着客户端和服务器可以同时发送数据。电话线路就是全双工的例子。为了在Web中实现全双工,Web Sockets是推荐的标准。一旦建立Web Socket连接,双方都可以同时交换消息。Web Sockets在TCP之上工作,不使用HTTP协议。
让我们来看看标准,在这个例子中是RFC-2616。在第8.1.1段中,我们发现持续连接:
- HTTP requests and responses can be pipelined on a connection.
Pipelining allows a client to make multiple requests without
waiting for each response, allowing a single TCP connection to
be used much more efficiently, with much lower elapsed time.
然后在文档稍后的部分:
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.
既然两种情况都清楚说明了客户端可以在不等待响应的情况下发送请求,我认为可以安全的说HTTP 1.1支持全双工。
编辑:在RFC-7230中,这个语句被替换了RFC-2616的一部分。
A client that supports persistent connections MAY "pipeline" its
requests (i.e., send multiple requests without waiting for each
response). A server MAY process a sequence of pipelined requests in
parallel if they all have safe methods (Section 4.2.1 of [RFC7231]),
but it MUST send the corresponding responses in the same order that
the requests were received.
大多数实现都允许全双工的HTTP(对于2xx响应)。
可在以下链接中找到详细讨论:
https://datatracker.ietf.org/doc/html/draft-zhu-http-fullduplex