Search code examples
promisehttp2

http2: order of push promise data


The spec says:

The server SHOULD send PUSH_PROMISE (Section 6.6) frames prior to sending any frames that reference the promised responses. This avoids a race where clients issue requests prior to receiving any PUSH_PROMISE frames.

For example, if the server receives a request for a document containing embedded links to multiple image files and the server chooses to push those additional images to the client, sending PUSH_PROMISE frames before the DATA frames that contain the image links ensures that the client is able to see that a resource will be pushed before discovering embedded links.

In the example given, I assume it would be okay for the server to send the image data before or after the "document containing embedded links to multiple image files".

Are all of these allowed?

Series A

  1. client requests document
  2. server sends PUSH_PROMISE of images
  3. server sends document
  4. server sends images

Series B

  1. client requests document
  2. server sends PUSH_PROMISE of images
  3. server sends images
  4. server sends document

Series C

  1. client requests document
  2. server sends PUSH_PROMISE of images
  3. server sends images/document concurrently, i.e. frames are interspersed

(In all cases, When the client makes a request for the images, it blocks on them being received locally on the promised stream id.)


Solution

  • All three options are viable for a server. For example, Jetty implements option C.

    However, I would not make any assumption on the behavior of the client, assuming that it will wait because it received the PUSH_PROMISE.

    For example, if the client urgently needs one of the resources that have been promised, it may cancel the pushed resource and issue a request for that resource with a high priority.