javascripthttpbrowserhttp2server-push

What happens when triggering a GET request while a http2 push is in-flight for the same resource


What happens when triggering a single GET request, while simultaneously a http2 push is in-flight for the same resource?

What is the specified behavior and what do the browsers actually do?

An example scenario could look like this:

at time 0: GET / (get document) and the server pushes /data.json
at time 1: GET /data.json (triggered by script, while the h2 push is still not finished / in-flight)

Will this result in two calls towards the server? Is this behavior specified or browser specific, e.g. in Chromium maybe via the HTTP Cache:

The cache implements a single writer - multiple reader lock so that only one network request for the same resource is in flight at any given time. https://www.chromium.org/developers/design-documents/network-stack/http-cache


Solution

  • The HTTP/2 specification in RFC 7540 says:

    Once a client receives a PUSH_PROMISE frame and chooses to accept the pushed response, the client SHOULD NOT issue any requests for the promised response until after the promised stream has closed.

    So it seems to be likely that the request will wait for the push response to be delivered, if the server does not take too long to start sending:

    If the client determines, for any reason, that it does not wish to
    receive the pushed response from the server or if the server takes
    too long
    to begin sending the promised response, the client can send
    a RST_STREAM frame, using either the CANCEL or REFUSED_STREAM code
    and referencing the pushed stream's identifier.