Execute a listener when a response is about to write headers
Execute a listener when a response is about to write headers.
$ npm install on-headers
var onHeaders = require'on-headers'
This will add the listener
listener to fire when headers are emitted for
The listener is passed the
response object as it's context (
this). Headers are
considered to be emitted only once, right before they are sent to the client.
When this is called multiple times on the same
listeners are fired
in the reverse order they were added.
var http = require'http'var onHeaders = require'on-headers'httpcreateServeronRequestlisten3000// add if not set by end of requestif !thisgetHeader'X-Powered-By'thisaddHeader'X-Powered-By' 'Node.js'onHeadersres addPoweredByressetHeader'Content-Type' 'text/plain'resend'hello!'