feat: add writeEarlyHints helper for HTTP 103 Early Hints support#378
feat: add writeEarlyHints helper for HTTP 103 Early Hints support#378bilal-azam wants to merge 1 commit into
Conversation
|
Hi @bilal-azam, Thanks for working on this. I think the idea of supporting Early Hints as middleware makes sense. That said, my preference would be to keep the public API narrower:
earlyHints({
link: '</styles.css>; rel=preload; as=style',
})
earlyHints({
link: (c) =>
`</themes/${c.req.query('theme')}.css>; rel=preload; as=style`,
})Allowing I would also expect the middleware to warn only once per middleware instance when The existing HTTP/1.1 and HTTP/2 integration tests look valuable and should mostly remain reusable. They would mainly need to be adapted to the middleware-only API, with coverage added for a dynamic |
Summary
Implements Early Hints (HTTP 103) support at the runtime layer, following
@yusukebe's direction in honojs/hono#5046 that this belongs in the runtime
adapter rather than Hono core.
Adds an exported
writeEarlyHints(c, hints)helper that calls Node's nativeresponse.writeEarlyHints()through the existingHttpBindings, lettingapplications send preload/preconnect Link headers before the response is ready:
Behaviour
false(no-op) instead of throwing when: the runtime/Node versionlacks
writeEarlyHints, or headers are already sent — safe to call in codeshared across runtimes
engines]Tests
Docs
README section added with the preload example.
Closes [node-server tracking issue if opened]; ref honojs/hono#5046.