HTTP/2 Push Multiple Responses from Single Worker Request?

Since a major use case for workers is to compose responses from multiple endpoints, is there a way to push multiple responses back to the client?

My use case specifically is to send back a mix of json and images without making subsequent worker or client side requests…

Any thoughts on an ideal approach?

Do you mean merging multiple responses or sending multiple responses separately to a single request?

I am able to merge using:

But ideally it would be nice to have something like multiple responses. I’m not even sure if this is possible. It’s my first attempt at something like this.

Not even possible as far as I know from the spec. Once you send one the request is closed, you can’t reply multiple times to one single request.

Good to know.

I was successful at writing multiple requests to a single readable stream using the TransformStream API.

However, the only technical bottleneck now seems to be using writers one must write sequentially to the stream (locks and what not) as well as the concurrent subrequest limit of 6: 2019/9/19 Workers Runtime Release Notes -- Concurrent Subrequest Limit

For now, it seems to function ok, especially after the responses are cached, since then there is no latency and the response body is piped to the stream and the loop continues almost instantly.

However, I would like to see more work done in combining responses and supporting concurrent subrequests. It seems like an excellent use case for workers to compose and enrich data requests.