
Product
Introducing Socket Firewall Enterprise: Flexible, Configurable Protection for Modern Package Ecosystems
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.
@graphistry/fastify-response-time
Advanced tools
Add X-Response-Time header at each request (in ms) for Fastify
Add X-Response-Time header at each request for Fastify. The unit used is milliseconds.
Add Server-Timing header, that could be used to pass timing server to client (useful to debug).
You could find some documentation at W3C Server-Timing documentation.
You need to use Fastify version 0.31 or newer, the hook used (onSend) was added in this version
If you need older Fastify version, use version 1.0.1 of this plugin
npm install --save fastify-response-time
Add it to you project with register and you are done!
// Register the plugin
fastify.register(require("fastify-response-time"));
// Define a new route in hapijs notation
fastify.route({
method: "GET",
url: "/header-hapi",
handler: (request, reply) => {
reply.send();
}
});
// Define a new route in express notation
fastify.get("/header-express", (request, reply) => {
reply.send();
});
// Add server timing information
fastify.get("/header-express", (request, reply) => {
reply.setServerTiming("cache", 5.3, "Cache read");
reply.send();
});
Both examples responds with:
< HTTP/1.1 200 OK
< Content-Type: application/json
< Content-Length: 17
< X-Response-Time: 0.08
< Date: Fri, 15 Sep 2017 21:14:33 GMT
< Connection: keep-alive
<
This plugin allow you to specify options:
header can be used to change default header name to something else (X-Response-Time by default)digits to specify the number of digits in the response (2 by default, so 1.03)reply.setServerTiming usagereply.setServerTiming( name , duration , description ) => boolean
With:
name: [mandatory] the name of the measure, and must be unique. Any already existing value will not be replacedduration: [optional] the duration, that must be an integer or float. If not needed, pass 0 or nulldescription: [optional] the description is needed. It must be a stringtrue if the measure is added the the list that will be send with the request, false is the name already
existsThe response will be:
< HTTP/1.1 200 OK
< Content-Type: application/json
< Content-Length: 17
< X-Response-Time: 0.08
< Server-Timing: cache;dur=5.3;desc="Cache read"
< Date: Fri, 15 Sep 2017 21:14:33 GMT
< Connection: keep-alive
<
FAQs
Add X-Response-Time header at each request (in ms) for Fastify
We found that @graphistry/fastify-response-time demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.

Security News
Open source dashboard CNAPulse tracks CVE Numbering Authorities’ publishing activity, highlighting trends and transparency across the CVE ecosystem.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.