# request-hash

> Generate a hash from an express Request or http.IncomingMessage

Latest version **1.0.6** (published 2022-12-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install request-hash
pnpm add request-hash
yarn add request-hash
bun add request-hash
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2022-12-01 |
| First published | 2018-09-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=10 |
| Dependencies | 1 |
| Unpacked size | 8.3 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Ruy Adorno |
| Maintainers | ruyadorno |
| Keywords | express, request, hash, sha, uuid, http, https, IncomingMessage, md5, crypto, fingerprint |

## Links

- npm: https://www.npmjs.com/package/request-hash
- Repository: https://github.com/ruyadorno/request-hash
- Homepage: https://github.com/ruyadorno/request-hash#readme
- Issues: https://github.com/ruyadorno/request-hash/issues
- npm.io page: https://npm.io/package/request-hash

## Dependencies (1)

- [cookie](https://npm.io/package/cookie.md) ^0.5.0

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.0.6 (latest) — 2022-12-01
- 1.0.5 — 2020-03-05
- 1.0.4 — 2019-05-24
- 1.0.3 — 2018-10-01
- 1.0.2 — 2018-09-30
- 1.0.1 — 2018-09-29
- 1.0.0 — 2018-09-26

## README

# request-hash

[![NPM version][npm-image]][npm-url]
[![Build Status][travis-image]][travis-url]
[![Coverage percentage][coveralls-image]][coveralls-url]
[![License MIT][license-image]][license-url]

> Generate a hash from an express Request or http.IncomingMessage

## Features

- Highly configurable
  - Options to **hand-pick / filter** which **headers** and **cookies** to use in order to create the hash
  - BYO **serialization**, **encoding** and **hashing algorithm** with sane defaults
- Works with any [http.IncomingMessage](https://nodejs.org/api/http.html#http_class_http_incomingmessage) or [express.Request](http://expressjs.com/en/api.html#req)

## Installation

```sh
$ npm install --save request-hash
```

## Usage

Here's a simple example using an express app:

```js
const requestHash = require('request-hash');
const express = require('express')
const app = express()
const port = 3000

// Initialize hash method using custom options
const hash = requestHash({ serializer: JSON.stringify, algorithm: 'md5' });

app.get('/', (req, res) => res.send(hash(req)))

app.listen(port, () => console.log(`Example app listening on port ${port}!`))
```

## API

The API exposes an initialization function which receives the options in order to customize the hash, this main funciton returns another function that actually performs the hashing.

### requestHash(options)

```js
const requestHash = require('request-hash');
requestHash({
  algorithm: 'sha256',
  encoding: 'hex',
  expand: false,
  cookies: undefined, // undefined means all cookies are going to be used as-is
  headers: undefined, // undefined means all headers are going to be used as-is
  serializer: undefined // undefined means custom serialize function is going to be used
});
```

#### Options

- **algorithm:** `<string>` Defines which hash algorithm to use, [possible values depends on the supported OpenSSL version in the platform](https://nodejs.org/api/crypto.html#crypto_crypto_createhash_algorithm_options). Examples are `sha256`, `sha512`, `md5`, etc.
- **digest:** `<string>` Defines a custom encoding to be used, possible values are: `hex`, `latin1`, `base64`.
- **serializer** `<function>` An object serialization function to be used, if undefined uses a custom implementation
- **expand:** `<boolean>` Allows you to bypass the hash algorithm, just returns the concatenated elements
- **cookies:** `<array>` List of cookie keys to be used to create the unique hash, defaults to using all elements
- **headers:** `<array>` List of header keys to be used to create the unique hash, defaults to using all elements

### hash(request:http.IncomingMessage)

```js
const requestHash = require('request-hash');
const hash = requestHash();

hash(req);
```

## Alternatives

- [incoming-message-hash](https://github.com/flickr/incoming-message-hash)

## License

MIT © [Ruy Adorno](http://ruyadorno.com)


[npm-image]: https://badge.fury.io/js/request-hash.svg
[npm-url]: https://npmjs.org/package/request-hash
[travis-image]: https://travis-ci.org/ruyadorno/request-hash.svg?branch=master
[travis-url]: https://travis-ci.org/ruyadorno/request-hash
[coveralls-image]: https://coveralls.io/repos/ruyadorno/request-hash/badge.svg
[coveralls-url]: https://coveralls.io/r/ruyadorno/request-hash
[license-image]: http://img.shields.io/badge/license-MIT-blue.svg?style=flat
[license-url]: https://raw.githubusercontent.com/ruyadorno/request-hash/master/LICENSE

---
_Source: https://npm.io/package/request-hash · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
