[ServiceWorker] Implement API to reject PUSH_PROMISEs sent by the server over HTTP/2 (#796)

[HTTP/2](http://http2.github.io/http2-spec/index.html) has support for the server pushing content to the client before the client requests it. This is specified as the server sending a [PUSH_PROMISE](http://http2.github.io/http2-spec/index.html#PUSH_PROMISE) to the client with (at least) the `method` and `url` to the resource. The server can then start sending the response to the client before the client has requested it. 

The spec does not specify how long the server should wait until it starts sending the response, so it can send it right away or it can choose to wait for a little while. If, while waiting, the server receives a [RST_STREAM](http://http2.github.io/http2-spec/index.html#RST_STREAM) message from the client on the (stream of the) resource, then the server should [interpret that as the client having rejected the content](http://http2.github.io/http2-spec/index.html#StreamStatesFigure). This can be done for example if the client already has the content in it's cache, and therefore doesn't need it. 

It would be useful if this could be handled by the ServiceWorker, since the ServiceWorker has a cache. The ServiceWorker could have a `pushPromise` event with the url as part of the event object, and a `reject` method that sends the `RST_STREAM` to the server. This could then be used to check if the url is in the ServiceWorkers cache, for example:

```js
this.oninstalled = function(){
  caches.set('myCache', new Cache());
}

this.addEventListener('pushPromise', function(event){
  //if the request url is in the cache,
  //then we don't need the server to send it to us,
  //so we reject it
  caches.match('myCache', event.request.url).then(event.reject);
});
```

---
Reply to this email directly or view it on GitHub:
https://github.com/slightlyoff/ServiceWorker/issues/796

Received on Thursday, 3 December 2015 20:07:42 UTC