了解 HTTP2 服务器推送和多路复用
Understanding HTTP2 server push and multiplexing
据我了解,多路复用的意思是客户端只需要与服务器建立一个TCP连接,它就可以同时发送多个请求,而不必等待一个请求的响应再继续另一个请求.所以如果我同时发送3个请求,也有3个响应流。
而对于服务器推送,客户端向服务器发送一个请求,服务器然后猜测客户端需要它请求的资源以外的其他资源(也称为承诺),因此它发送推送承诺流来提示客户端与 URL 的额外资源。客户端可以选择是否请求这些额外的资源。
我的问题是:
- For any response sent from the server to the client, does it have to be a request initiated first? I mean, it I created a connection to
the server, I did not send any request. Could I be getting responses
from server via server push? In multiplexing, I get same number of
responses for same number of requests. In server push, I can get
multiple responses for one request. So does there always have to be a
request first?
- In server push, when a promise stream is sent by the server to the client containing the URL of the additional resources, does that mean
the server will only push the additional resources only when the
client accepts the promises?
[the server] sends push promise streams hinting the client with the URL of the additional resources. The client may choose to request those additional resources or not.
这是不正确的。当服务器向客户端发送PUSH_PROMISE
时,服务器将发送与该推送资源关联的资源内容。
客户端唯一可以做的就是通过 RST_STREAM
帧重置推送流,但很可能整个推送资源已经在运行中,因此重置推送流没有效果:客户端将接收推送的资源字节,如果不感兴趣可以丢弃它们。
回答您的具体问题:
是的,来自服务器的响应总是由客户端发起的。如果客户端不向服务器发送任何请求,则服务器无法向客户端推送。即使在服务器推送的情况下,客户端始终通过发出请求来启动流,并且服务器推送始终与该 "parent" 请求相关联。
PUSH_PROMISE
帧是服务器向客户端指示服务器将要推送什么资源。客户端不"accept"推送,服务器强制他们给客户端。客户端唯一能做的就是重置与推送资源关联的流;正如我所说,服务器在收到来自客户端的 RST_STREAM
帧时可能已经推送了整个资源。
据我了解,多路复用的意思是客户端只需要与服务器建立一个TCP连接,它就可以同时发送多个请求,而不必等待一个请求的响应再继续另一个请求.所以如果我同时发送3个请求,也有3个响应流。
而对于服务器推送,客户端向服务器发送一个请求,服务器然后猜测客户端需要它请求的资源以外的其他资源(也称为承诺),因此它发送推送承诺流来提示客户端与 URL 的额外资源。客户端可以选择是否请求这些额外的资源。
我的问题是:
- For any response sent from the server to the client, does it have to be a request initiated first? I mean, it I created a connection to the server, I did not send any request. Could I be getting responses from server via server push? In multiplexing, I get same number of responses for same number of requests. In server push, I can get multiple responses for one request. So does there always have to be a request first?
- In server push, when a promise stream is sent by the server to the client containing the URL of the additional resources, does that mean the server will only push the additional resources only when the client accepts the promises?
[the server] sends push promise streams hinting the client with the URL of the additional resources. The client may choose to request those additional resources or not.
这是不正确的。当服务器向客户端发送PUSH_PROMISE
时,服务器将发送与该推送资源关联的资源内容。
客户端唯一可以做的就是通过 RST_STREAM
帧重置推送流,但很可能整个推送资源已经在运行中,因此重置推送流没有效果:客户端将接收推送的资源字节,如果不感兴趣可以丢弃它们。
回答您的具体问题:
是的,来自服务器的响应总是由客户端发起的。如果客户端不向服务器发送任何请求,则服务器无法向客户端推送。即使在服务器推送的情况下,客户端始终通过发出请求来启动流,并且服务器推送始终与该 "parent" 请求相关联。
PUSH_PROMISE
帧是服务器向客户端指示服务器将要推送什么资源。客户端不"accept"推送,服务器强制他们给客户端。客户端唯一能做的就是重置与推送资源关联的流;正如我所说,服务器在收到来自客户端的RST_STREAM
帧时可能已经推送了整个资源。