This repository has been archived on 2018-10-12. You can view files and clone it, but cannot push or open issues or pull requests.
node-task/node_modules/express-session/node_modules/on-headers
2014-09-23 14:54:05 -04:00
..
.npmignore Add bcrypt and session modules 2014-09-23 14:54:05 -04:00
History.md Add bcrypt and session modules 2014-09-23 14:54:05 -04:00
index.js Add bcrypt and session modules 2014-09-23 14:54:05 -04:00
LICENSE Add bcrypt and session modules 2014-09-23 14:54:05 -04:00
package.json Add bcrypt and session modules 2014-09-23 14:54:05 -04:00
README.md Add bcrypt and session modules 2014-09-23 14:54:05 -04:00

on-headers

NPM Version Node.js Version Build Status Coverage Status Gittip

Execute a listener when a response is about to write headers.

Install

$ npm install on-headers

API

var onHeaders = require('on-headers')

onHeaders(res, listener)

This will add the listener listener to fire when headers are emitted for res. 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 res, the listeners are fired in the reverse order they were added.

Examples

var http = require('http')
var onHeaders = require('on-headers')

http
.createServer(onRequest)
.listen(3000)

function addPoweredBy() {
  // add if not set by end of request
  if (!this.getHeader('X-Powered-By')) {
    this.addHeader('X-Powered-By', 'Node.js')
  }
}

function onRequest(req, res) {
  onHeaders(res, addPoweredBy)

  res.setHeader('Content-Type', 'text/plain')
  res.end('hello!')
}

License

MIT