1

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

When I look HttpResponse.PushPromise 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.

Second public void PushPromise(string path, string method, NameValueCollection headers) that accepts sting method and 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 PUSH PROMISE header?

Matas Vaitkevicius
  • 58,075
  • 31
  • 238
  • 265

2 Answers2

3

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.

Christopher Currens
  • 29,917
  • 5
  • 57
  • 77
0

You'll want to pass headers for anything that will cause your response to vary (i.e. anything in your Vary response header). The biggest one I've found is compression.

Read those headers from the original client request and include them with your push promise, e.g.:

var headers = new NameValueCollection { { "accept-encoding", this.Request.Headers["accept-encoding"] } };
this.Response.PushPromise("~/Scripts/jquery.js", "GET", headers);`
ejohnson
  • 655
  • 7
  • 18
  • I'm not convinced about this. I think you would add a header here only if the **contents** of the file would vary based on that particular header. The content of the uncompressed file never changes so this does nothing useful. I think the need for specifying `headers` is a very specialized case that most people need not worry about. Perhaps if the *content* of the file varied based on the browser's language then you would use this, but obviously `jquery.js` is a static file here so the content doesn't change. If the file was dynamic based on language you could use it. – Simon_Weaver Feb 23 '17 at 22:24