Matas Vaitkevicius Matas Vaitkevicius - 1 year ago 113
C# Question

.NET 4.6 HttpResponse.PushPromise methods to manage http/2 PUSH_PROMISE header

I am a bit confused about PUSH PROMISE http/2 header handling in


When I look
there are two overloads:

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)
that accepts
sting method
NameValueCollection headers
which I am failing to understand.

Why would I want to pass method (assuming HttpMethod like GET, POST, etc) and collection of headers inside

Answer Source

From reading the HTTP/2 spec (Section 8.2), here is what I gather:

Passing the method

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.

Passing headers

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.

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.