Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Hold on, we're currently generating a fresh version of this report
Generated on May 6, 2024 via pnpm

on-headers 1.0.2

Execute a listener when a response is about to write headers
Package summary
Share
0
issues
1
license
1
MIT
Package created
14 May 2014
Version published
22 Feb 2019
Maintainers
1
Total deps
1
Direct deps
0
License
MIT

Issues

0
This package has no issues

Licenses

MIT License

Permissive
OSI Approved
This is a human-readable summary of (and not a substitute for) the license. Disclaimer.
Can
commercial-use
modify
distribute
sublicense
private-use
Cannot
hold-liable
Must
include-copyright
include-license
1 Packages, Including:
on-headers@1.0.2
Disclaimer

This deed highlights only some of the key features and terms of the actual license. It is not a license and has no legal value. You should carefully review all of the terms and conditions of the actual license before using the licensed material.

Sandworm is not a law firm and does not provide legal services. Distributing, displaying, or linking to this deed or the license that it summarizes does not create a lawyer-client or any other relationship.

Direct Dependencies

0
All Dependencies CSV
β“˜ This is a list of on-headers 's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.
NameVersionSizeLicenseTypeVulnerabilities

Visualizations

Frequently Asked Questions

What does on-headers do?

The npm package "on-headers" is primarily used to execute a listener when a web server's response is about to write headers. In essence, it allows you to monitor and intervene in the process of setting HTTP headers before they are sent to the client. This can be incredibly useful for adding or modifying headers as per the application's needs, without disrupting the flow of other operations in the server application.

How do you use on-headers?

To use "on-headers", you first need to install the package using the npm install command like so:

$ npm install on-headers

Once installed, you require it in your Node.js file with this command:

var onHeaders = require('on-headers')

To add a listener that will execute when headers are emitted for response, you use the onHeaders(res, listener) function where res is the response object and listener is the function to fire. For example:

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!')
}

In the example above, the package triggers the addPoweredBy function just before the headers are written on the response object. If the 'X-Powered-By' header has not been set, it sets it to 'Node.js'.

Where are the on-headers docs?

The official documentation for "on-headers" can be found within the README file on its GitHub repository at https://github.com/jshttp/on-headers. The documentation provides more details on the API and its usage. Additionally, it provides instructions on how to install the package, test it, and a few examples demonstrating its usage.