{"name":"on-headers","description":"Execute a listener when a response is about to write headers","version":"1.0.0","author":{"name":"Douglas Christopher Wilson","email":"doug@somethingdoug.com"},"license":"MIT","keywords":["event","headers","http","onheaders"],"repository":{"type":"git","url":"https://github.com/jshttp/on-headers"},"dependencies":{},"devDependencies":{"istanbul":"0.3.0","mocha":"~1.21.4","supertest":"~0.13.0"},"engines":{"node":">= 0.8.0"},"scripts":{"test":"mocha --reporter spec --bail --check-leaks test/","test-cov":"istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/","test-travis":"istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/"},"readme":"# on-headers\n\n[![NPM Version](https://img.shields.io/npm/v/on-headers.svg?style=flat)](https://www.npmjs.org/package/on-headers)\n[![Node.js Version](https://img.shields.io/badge/node.js->=_0.8-blue.svg?style=flat)](http://nodejs.org/download/)\n[![Build Status](https://img.shields.io/travis/jshttp/on-headers.svg?style=flat)](https://travis-ci.org/jshttp/on-headers)\n[![Coverage Status](https://img.shields.io/coveralls/jshttp/on-headers.svg?style=flat)](https://coveralls.io/r/jshttp/on-headers)\n[![Gittip](https://img.shields.io/gittip/dougwilson.svg?style=flat)](https://www.gittip.com/dougwilson/)\n\nExecute a listener when a response is about to write headers.\n\n## Install\n\n```sh\n$ npm install on-headers\n```\n\n## API\n\n```js\nvar onHeaders = require('on-headers')\n```\n\n### onHeaders(res, listener)\n\nThis will add the listener `listener` to fire when headers are emitted for `res`.\nThe listener is passed the `response` object as it's context (`this`). Headers are\nconsidered to be emitted only once, right before they are sent to the client.\n\nWhen this is called multiple times on the same `res`, the `listener`s are fired\nin the reverse order they were added.\n\n## Examples\n\n```js\nvar http = require('http')\nvar onHeaders = require('on-headers')\n\nhttp\n.createServer(onRequest)\n.listen(3000)\n\nfunction addPoweredBy() {\n  // add if not set by end of request\n  if (!this.getHeader('X-Powered-By')) {\n    this.addHeader('X-Powered-By', 'Node.js')\n  }\n}\n\nfunction onRequest(req, res) {\n  onHeaders(res, addPoweredBy)\n\n  res.setHeader('Content-Type', 'text/plain')\n  res.end('hello!')\n}\n```\n\n## License\n\n[MIT](LICENSE)\n","readmeFilename":"README.md","bugs":{"url":"https://github.com/jshttp/on-headers/issues"},"homepage":"https://github.com/jshttp/on-headers","_id":"on-headers@1.0.0","_shasum":"2c75b5da4375513d0161c6052e7fcbe4953fca5d","_from":"https://registry.npmjs.org/on-headers/-/on-headers-1.0.0.tgz","_resolved":"https://registry.npmjs.org/on-headers/-/on-headers-1.0.0.tgz"}