Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gajus/http-header
Utilities for working with HTTP headers.
https://github.com/gajus/http-header
header http nodejs
Last synced: 30 days ago
JSON representation
Utilities for working with HTTP headers.
- Host: GitHub
- URL: https://github.com/gajus/http-header
- Owner: gajus
- License: other
- Created: 2019-01-31T19:17:53.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-01-31T20:13:38.000Z (almost 6 years ago)
- Last Synced: 2024-10-05T13:48:25.335Z (about 1 month ago)
- Topics: header, http, nodejs
- Language: JavaScript
- Homepage:
- Size: 11.7 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# http-header
[![Travis build status](http://img.shields.io/travis/gajus/http-header/master.svg?style=flat-square)](https://travis-ci.org/gajus/http-header)
[![Coveralls](https://img.shields.io/coveralls/gajus/http-header.svg?style=flat-square)](https://coveralls.io/github/gajus/http-header)
[![NPM version](http://img.shields.io/npm/v/http-header.svg?style=flat-square)](https://www.npmjs.org/package/http-header)
[![Canonical Code Style](https://img.shields.io/badge/code%20style-canonical-blue.svg?style=flat-square)](https://github.com/gajus/canonical)
[![Twitter Follow](https://img.shields.io/twitter/follow/kuizinas.svg?style=social&label=Follow)](https://twitter.com/kuizinas)Utilities for working with HTTP headers.
## API
```js
import {
deleteHeader,
getHeader,
getHeaderName,
hasHeader,
HeaderNotFoundError,
InvalidHeaderNameError,
InvalidHeaderValueError,
setHeader,
setHeaderName
} from 'http-header';
import type {
HeaderNameType,
HeadersType,
HeaderValueType
} from 'http-header';deleteHeader(headers: HeadersType, name: HeaderNameType) => HeadersType;
getHeader(headers: HeadersType, name: HeaderNameType) => HeaderValueType;
getHeaderName(headers: HeadersType, name: HeaderNameType) => HeaderNameType;
hasHeader(headers: HeadersType, name: HeaderNameType) => boolean;
setHeader(headers: HeadersType, name: HeaderNameType, value: HeaderValueType) => HeadersType;
setHeaderName(headers: HeadersType, oldName: HeaderNameType, newName: HeaderNameType) => HeadersType;```
### Behaviour
#### `HeaderNotFoundError` error
`getHeader` and `getHeaderName` throw `HeaderNotFoundError` if the specified header cannot be found.
Use `hasHeader` to check if the header exists before using `getHeader` or `getHeaderName`, e.g.
```js
import {
hasHeader,
getHeader
} from 'http-header';if (hasHeader('Content-Type')) {
getHeader('Content-Type');
}```