# enforce-content-type

> Enforce Content-Type headers on request

Latest version **1.1.0** (published 2016-05-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install enforce-content-type
pnpm add enforce-content-type
yarn add enforce-content-type
bun add enforce-content-type
```

## 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.1.0 |
| Published | 2016-05-17 |
| First published | 2016-04-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Christoph Werner |
| Maintainers | gonsfx |
| Keywords | http, security, express, middleware, header, connect, content-type |

## Links

- npm: https://www.npmjs.com/package/enforce-content-type
- Repository: https://github.com/gonsfx/enforce_content_type
- Homepage: https://github.com/gonsfx/enforce_content_type#readme
- Issues: https://github.com/gonsfx/enforce_content_type/issues
- npm.io page: https://npm.io/package/enforce-content-type

## Dependencies (3)

- [lodash](https://npm.io/package/lodash.md) ^4.11.1
- [type-is](https://npm.io/package/type-is.md) ^1.6.12
- [http-status-codes](https://npm.io/package/http-status-codes.md) ^1.0.6

## 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.1.0 (latest) — 2016-05-17
- 1.0.0 — 2016-04-20

## README

Enforce Content-Type middleware
===============================
[![npm version](https://badge.fury.io/js/enforce-content-type.svg)](https://badge.fury.io/js/enforce-content-type)
[![Build Status](https://travis-ci.org/gonsfx/enforce-content-type.svg?branch=master)](https://travis-ci.org/gonsfx/enforce-content-type)
[![Coverage Status](https://coveralls.io/repos/github/gonsfx/enforce-content-type/badge.svg?branch=master)](https://coveralls.io/github/gonsfx/enforce-content-type?branch=master)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)

This middleware enforces the `Content-Type` header of requests to be a specified value.
If the header doesn't match that value, a HTTP status code 415 "Unsupported Media Type" is returned.

```javascript
var enforceContentType = require('enforce-content-type')

app.use(enforceContentType({
  type: 'application/json'
}))
```

It is also possible to specify multiple acceptable content types:

```javascript
app.use(enforceContentType({
  type: [
    'application/json',
    'multipart/form-data'
  ]
}))
```

Requests without a body are not enforced unless the `force` option is set to true:

```javascript
app.use(enforceContentType({
  force: true,
  type: 'application/json'
}))
```

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