Big update!Introducing GitHub Bot Commands. Learn more
Socket
Log inBook a demo

on-headers

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Issues
File Explorer

Advanced tools

on-headers

Execute a listener when a response is about to write headers

    1.0.2latest

Version published
Maintainers
1
Weekly downloads
18,197,653
decreased by-12.84%

Weekly downloads

Readme

Source

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

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

$ 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

Keywords

FAQs

What is on-headers?

Execute a listener when a response is about to write headers

Is on-headers popular?

The npm package on-headers receives a total of 14,719,503 weekly downloads. As such, on-headers popularity was classified as popular.

Is on-headers well maintained?

We found that on-headers demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.It has 1 open source maintainer collaborating on the project.

Last updated on 22 Feb 2019

Did you know?

Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install Socket
Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc