Feature Request — Runtime APIs: API for Early Hints #761
Replies: 2 comments 4 replies
-
Hi Marcus, Thanks for the suggestion. We prefer our issue tracker to track immediately-actionable issues (e.g. bugs) rather than long-term feature requests and ideas, so I will convert this to a discussion. |
Beta Was this translation helpful? Give feedback.
-
As a fan of the early hints work I would absolutely love to see this happen. One key challenge here is that there really isn't a standard way of expressing these just yet. Yielding a non-final export default {
async fetch(req, env, ctx) {
// send hints...
ctx.sendEarlyHints(new Headers('...'));
// do something
return new Response(...);
}
}; For me, this feels a bit more natural. Unfortunately it is not as simple as just adding this API. Internally, we make use of kj's HTTP implementation and have that woven throughout a number of places internally. The first step here, I believe, would be in teaching kj how to handle early hints, which I imagine is a non-trivial exercise. Once that is done, we could look at how to support this elsewhere. We would also have to make sure that other parts of our infrastructure can support us sending these, which is something that can be explored, but as Kenton points out, we've got a lot on the plate already and it is not clear that this is something that could be prioritized quickly. That said, if it is something that you're interested in exploring, with the warning that it may take some time and a lot of back and forth, I would encourage you to start digging into the details of kj to see how it could be done. I caution, however, it's likely to be a very complex change, and in the spirit of Zork, "It is pitch black. You are likely to be eaten by a grue." |
Beta Was this translation helpful? Give feedback.
-
Background:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/103
https://blog.cloudflare.com/early-hints/
For my application (and presumably others with this as a design goal), we can trivially determine (some of) the asset URLs we're going to need on the document load, far ahead of knowing what the status code will be. Currently, Workerd lacks an explicit facility for declaring early hints from the application, with Cloudflare's public offering requiring that the eventual response header be committed to extract them.
My potentially naive proposal here would be to accept generators as fetch handlers, allowing yields of
Response
objects with a 103 status, but a context object based API would seem to be viable too. Pursuing use of theResponse
object in either API would technically require either spec divergence or upstream agreement, asResponse
is spec'd to throw aRangeError
for status codes < 200.While I have very limited experience in the C++ world, it's very important to some of my employer's architectural goals/possibly a blocker to our ability to use workerd, so I'd be happy to try to work towards contributing this if we can establish agreement on desirability and API.
Beta Was this translation helpful? Give feedback.
All reactions