koa-latency-headers

0.0.4 • Public • Published

Koa Latency Header Middleware

This middleware adds two headers to the response.

  • x-request-received is set by the server with the timestamp of when the request was received
  • x-response-sent is set by the server with the timestamp of when the response was sent

More information on why to add these headers.

Example

npm install koa-latency-headers --save
var koa = require('koa')
var app = koa()
 
// Latency Header Middleware
var latency = require('koa-latency-headers')
 
// Set the x-request-received header
app.use(latency())
 
// Send the response body
app.use(function *(next){
 
  // Simulate processing delay
  yield (function() {
    var timeout = Math.floor((Math.random() * 25) + 25);
    return function (cb) {
      setTimeout(cb, timeout)
    }
  })()
 
  // Obligatory hello world
  this.body = 'Hello World'
  
})
 
// Listen for incoming requests
app.listen(1337)
 

Package Sidebar

Install

npm i koa-latency-headers

Weekly Downloads

1

Version

0.0.4

License

ISC

Last publish

Collaborators

  • montanaflynn