Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hex7c0/setheaders
boilerplate for res.setHeader, protection from being overridden for Nodejs
https://github.com/hex7c0/setheaders
header nodejs
Last synced: about 1 month ago
JSON representation
boilerplate for res.setHeader, protection from being overridden for Nodejs
- Host: GitHub
- URL: https://github.com/hex7c0/setheaders
- Owner: hex7c0
- License: apache-2.0
- Created: 2014-11-13T19:59:49.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2023-04-15T23:59:20.000Z (over 1 year ago)
- Last Synced: 2024-04-13T19:19:46.400Z (9 months ago)
- Topics: header, nodejs
- Language: JavaScript
- Homepage: https://github.com/hex7c0/setheaders
- Size: 166 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# [setheaders](https://github.com/hex7c0/setheaders)
[![NPM version](https://img.shields.io/npm/v/setheaders.svg)](https://www.npmjs.com/package/setheaders)
[![Linux Status](https://img.shields.io/travis/hex7c0/setheaders.svg?label=linux-osx)](https://travis-ci.org/hex7c0/setheaders)
[![Windows Status](https://img.shields.io/appveyor/ci/hex7c0/setheaders.svg?label=windows)](https://ci.appveyor.com/project/hex7c0/setheaders)
[![Dependency Status](https://img.shields.io/david/hex7c0/setheaders.svg)](https://david-dm.org/hex7c0/setheaders)
[![Coveralls](https://img.shields.io/coveralls/hex7c0/setheaders.svg)](https://coveralls.io/r/hex7c0/setheaders)boilerplate for res.setHeader, protection from being overridden and more!
## Installation
Install through NPM
```bash
npm install setheaders
```
or
```bash
git clone git://github.com/hex7c0/setheaders.git
```## API
inside nodejs project, set `pippo` as "X-Foo" header
```js
var setHeader = require('setheaders');setHeader(res, 'X-Foo', 'pippo');
```there are different shortcuts, instead of setting correct argument
```js
var setHeader = require('setheaders');var setProctedHeader = setHeader.setProctedHeader; // protected = true
var setOverrideHeader = setHeader.setOverrideHeader; // override = true
var setWritableHeader = setHeader.setWritableHeader; // writable = true
```### setheaders(res, name, value [, protected [, override [, writable] ] ])
#### options
- `res` - **Object** response to client *(default "required")*
- `name`- **String** header's name *(default "required")*
- `value` - **String** header's value *(default "required")*
- `[protected]` - **true** set protected header, from being overridden before they are written to response *(default "false")*
- `[override]` - **true** check if I'm trying to override a header *(default "false")*
- `[writable]` - **true** check if socket is writable, prevent write Error *(default "false")*## Examples
Take a look at my [examples](examples)
### [License Apache2](LICENSE)