You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
nau 64882fc513 get token for user, post users, get all users, post thought, get all thoughts. runs ok 8 years ago
..
HISTORY.md get token for user, post users, get all users, post thought, get all thoughts. runs ok 8 years ago
LICENSE get token for user, post users, get all users, post thought, get all thoughts. runs ok 8 years ago
README.md get token for user, post users, get all users, post thought, get all thoughts. runs ok 8 years ago
index.js get token for user, post users, get all users, post thought, get all thoughts. runs ok 8 years ago
package.json get token for user, post users, get all users, post thought, get all thoughts. runs ok 8 years ago

README.md

on-headers

NPM Version NPM Downloads Node.js Version Build Status Test Coverage

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

Installation

$ 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() {
  // set if not set by end of request
  if (!this.getHeader('X-Powered-By')) {
    this.setHeader('X-Powered-By', 'Node.js')
  }
}

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

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

Testing

$ npm test

License

MIT