Big update!Announcing Socket for GitHub 1.0. Learn more
Socket
BlogLoveFAQ
Install
Log in

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
17,910,327
increased by1.35%

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 16,995,729 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. It has 1 open source maintainer collaborating on the project.

Last updated on 22 Feb 2019
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