on-headers

WebJar for on-headers

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

on-headers
Last Version

Last Version

1.0.2
Release Date

Release Date

Type

Type

jar
Description

Description

on-headers
WebJar for on-headers
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/jshttp/on-headers

Download on-headers

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/on-headers/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>on-headers</artifactId>
    <version>1.0.2</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/on-headers/
implementation 'org.webjars.npm:on-headers:1.0.2'
// https://jarcasting.com/artifacts/org.webjars.npm/on-headers/
implementation ("org.webjars.npm:on-headers:1.0.2")
'org.webjars.npm:on-headers:jar:1.0.2'
<dependency org="org.webjars.npm" name="on-headers" rev="1.0.2">
  <artifact name="on-headers" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='on-headers', version='1.0.2')
)
libraryDependencies += "org.webjars.npm" % "on-headers" % "1.0.2"
[org.webjars.npm/on-headers "1.0.2"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

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

org.webjars.npm
Low-Level JavaScript HTTP-related Modules

Versions

Version
1.0.2
1.0.1