客户端发起的请求方法类型

Client initiated request method types

http2 spec 说:

HTTP/2 allows a server to pre-emptively send (or "push") responses (along with corresponding "promised" requests) to a client in association with a previous client-initiated request.

客户端发起请求的方式是否有限制? 我猜这通常是GET,但我想知道是否有限制它不能是其他东西。

对于什么类型的请求可以导致推送响应没有限制,但是there are restrictions as to what items can be pushed(基本上是 GET 请求):

Promised requests MUST be cacheable (see [RFC7231], Section 4.2.3), MUST be safe (see [RFC7231], Section 4.2.1), and MUST NOT include a request body.

因此,如果提交表单使用 POST 请求和 returns HTML,那么推送 HTML 所需的资源可能很有意义。

推送的资源are not pushed into the normal HTTP/2 cache used by the browser but into a separate “push cache”。这是与该连接相关联的短期缓存。推送的资源仅从该推送缓存中检索并在需要它们的东西将它们从该缓存中拉出时更永久地保存。

因此,您应该只推送发起者(或紧随其后的另一个请求)需要的资源。因此,如果您有一个导致推送资源的 OPTIONS 请求,它真的会被使用吗? OPTIONS请求没有限制导致推送,但是如果推送后没有立即使用推送的资源,则可能是浪费推送。