Fastify Early Hints
Draft proposal of plugin handling the HTTP 103 code. Based on : https://github.com/fastify/fastify/issues/2683
Install
npm i fastify-early-hints
Usage
eh.add
: Every call writes to the socket and returns a promise. Altought all the promises created throught the reply lifecycle are awaited in theonSend
hook.
const Fastify = ;const eh = ; const fastify = ;fastify; fastify; const start = async { try await fastify; fastifylog; catch err fastifylog; process; };;
Result
$ curl -D - http://localhost:3000
HTTP/1.1 103 Early Hints
Link: </style.css>; rel=preload; as=style
Link: </script.js>; rel=preload; as=script
HTTP/1.1 103 Early Hints
Link: </style.css>; rel=preload; as=style
Link: </script.js>; rel=preload; as=script
Link: <//example.com>; rel=preload; as=style
Link: <//example.com>; rel=preload; as=style; crossorigin
Link: <//example.com>; rel=preconnect
Link: <//example2.com>; rel=preconnect; crossorigin
Link: <//example3.com>; rel=preconnect; crossorigin=use-credentials
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
content-length: 17
Date: Thu, 12 Nov 2020 22:45:54 GMT
Connection: keep-alive
{"hello":"world"}
Todo
- Handling different cases combinations
- improve tests
References
License
Licensed under MIT.