Ohm-Management - Projektarbeit B-ME
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.

README.md 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # on-headers
  2. [![NPM Version][npm-image]][npm-url]
  3. [![NPM Downloads][downloads-image]][downloads-url]
  4. [![Node.js Version][node-version-image]][node-version-url]
  5. [![Build Status][travis-image]][travis-url]
  6. [![Test Coverage][coveralls-image]][coveralls-url]
  7. Execute a listener when a response is about to write headers.
  8. ## Installation
  9. ```sh
  10. $ npm install on-headers
  11. ```
  12. ## API
  13. ```js
  14. var onHeaders = require('on-headers')
  15. ```
  16. ### onHeaders(res, listener)
  17. This will add the listener `listener` to fire when headers are emitted for `res`.
  18. The listener is passed the `response` object as it's context (`this`). Headers are
  19. considered to be emitted only once, right before they are sent to the client.
  20. When this is called multiple times on the same `res`, the `listener`s are fired
  21. in the reverse order they were added.
  22. ## Examples
  23. ```js
  24. var http = require('http')
  25. var onHeaders = require('on-headers')
  26. http
  27. .createServer(onRequest)
  28. .listen(3000)
  29. function addPoweredBy() {
  30. // set if not set by end of request
  31. if (!this.getHeader('X-Powered-By')) {
  32. this.setHeader('X-Powered-By', 'Node.js')
  33. }
  34. }
  35. function onRequest(req, res) {
  36. onHeaders(res, addPoweredBy)
  37. res.setHeader('Content-Type', 'text/plain')
  38. res.end('hello!')
  39. }
  40. ```
  41. ## Testing
  42. ```sh
  43. $ npm test
  44. ```
  45. ## License
  46. [MIT](LICENSE)
  47. [npm-image]: https://img.shields.io/npm/v/on-headers.svg
  48. [npm-url]: https://npmjs.org/package/on-headers
  49. [node-version-image]: https://img.shields.io/node/v/on-headers.svg
  50. [node-version-url]: http://nodejs.org/download/
  51. [travis-image]: https://img.shields.io/travis/jshttp/on-headers/master.svg
  52. [travis-url]: https://travis-ci.org/jshttp/on-headers
  53. [coveralls-image]: https://img.shields.io/coveralls/jshttp/on-headers/master.svg
  54. [coveralls-url]: https://coveralls.io/r/jshttp/on-headers?branch=master
  55. [downloads-image]: https://img.shields.io/npm/dm/on-headers.svg
  56. [downloads-url]: https://npmjs.org/package/on-headers