Detalhes do pacote

xprezzo-on-headers

xprezzo3.8kMIT1.1.3

Execute a listener when a response is about to write headers

event, headers, http, onheaders

readme (leia-me)

xprezzo-on-headers

Execute a listener when a response is about to write headers

Installation

This is a Node.js module available through the npm registry. Installation is done using the npm install command:

$ npm install xprezzo-on-headers

API

var onHeaders = require('xprezzo-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('xprezzo-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', 'Xprezzo')
  }
}

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

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

Testing

$ npm test

People

Xprezzo and related projects are maintained by Cloudgen Wong.

License

MIT

changelog (log de mudanças)

1.1.3 / 2022-05-11

  • depds: updated
  • depds eslint updated to 8.15.0
  • depds eslint-config-standard updated to 17.0.0
  • depds eslint-plugin-import updated to 2.26.0
  • depds eslint-plugin-markdown updated to 2.2.1
  • depds eslint-plugin-promise updated to 6.0.0
  • depds mocha updated to 10.0.0
  • remove eslint-plugin-standard
  • depds supertest updated to 6.2.3

1.1.2 / 2020-04-25

  • depds mocha to 8.3.1

1.1.1 / 2020-10-17

  • depds eslint to 7.11.0
  • depds eslint-plugin-import to 2.22.1
  • depds mocha to 8.2.0

1.1.0 / 2020-10-05

  • depds updated

1.0.0 / 2020-10-05

  • Initial release