.NET 4.6 HttpResponse.PushPromise方法来管理http/2 PUSH_PROMISE标头 [英] .NET 4.6 HttpResponse.PushPromise methods to manage http/2 PUSH_PROMISE header
问题描述
对于 PUSH承诺
I am a bit confused about PUSH PROMISE http/2 header handling in .NET4.6
.
当我看 HttpResponse.PushPromise
有两个重载:
接受资源路径的人 public void PushPromise(string path)
-假设然后读取资源并将二进制文件发送到客户端.
One that accepts path to resource public void PushPromise(string path)
- am assuming resource is then read and binary sent across to client.
第二 public void PushPromise(string path, string method, NameValueCollection headers)
接受我无法理解的sting method
和NameValueCollection headers
.
Second public void PushPromise(string path, string method, NameValueCollection headers)
that accepts sting method
and NameValueCollection headers
which I am failing to understand.
我为什么要在PUSH PROMISE
标头内传递方法(假设HttpMethod像GET,POST等)和标头集合?
Why would I want to pass method (assuming HttpMethod like GET, POST, etc) and collection of headers inside PUSH PROMISE
header?
推荐答案
通过阅读HTTP/2 规范(第8.2节),这是我收集的信息:
From reading the HTTP/2 spec (Section 8.2), here is what I gather:
PUSH_PROMISE
帧必须是可缓存和安全.您可以选择使用GET
和HEAD
,因为这是定义为安全和可缓存的仅有的两个http方法.
PUSH_PROMISE
frames are required to be cacheable and safe. You have the option of using GET
and HEAD
, as those are the only two http methods that are defined as both safe and cacheable.
由于需要PUSH_PROMISE
帧是可缓存的,因此可以将其添加到Promise中特定的Cache-Control
指令. 规范的8.2.2节规定客户拥有可以选择下载承诺的流并拒绝它的选项,我想如果客户发现缓存中具有最新版本的资源,客户端就会这样做.
Since PUSH_PROMISE
frames are required to be cacheable, this could be used to add specific Cache-Control
directives to the promise. Section 8.2.2 of the spec states that a client has the option to download the promised stream and can refuse it, which I imagine a client would do if it found that it had an up-to-date version of the resource in its cache.
控制缓存是我可以看到为什么传递标头的最明显原因,但是也可能还有其他原因.如果您正在编写自定义客户端,则可以使用某些X-Header向客户端提供其他提示(与缓存无关),以便它可以决定是否要接受承诺的流.
Controlling caching is the most obvious reason I can see for why you might pass headers, but there may be other reasons as well. If you're writing a custom client, you may use certain X-Headers to provide other hints (that aren't related to caching) to the client so it can decide whether or not it wants to accept the promised stream.
这篇关于.NET 4.6 HttpResponse.PushPromise方法来管理http/2 PUSH_PROMISE标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!