https://github.com/codepunkt/enforce-content-type
Connect/Express middleware to enforce Content-Type headers on request
https://github.com/codepunkt/enforce-content-type
Last synced: 5 months ago
JSON representation
Connect/Express middleware to enforce Content-Type headers on request
- Host: GitHub
- URL: https://github.com/codepunkt/enforce-content-type
- Owner: codepunkt
- License: mit
- Created: 2016-04-20T10:43:30.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-05-17T08:51:52.000Z (over 9 years ago)
- Last Synced: 2024-11-19T23:42:05.839Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 6.84 KB
- Stars: 5
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Enforce Content-Type middleware
===============================
[](https://badge.fury.io/js/enforce-content-type)
[](https://travis-ci.org/gonsfx/enforce-content-type)
[](https://coveralls.io/github/gonsfx/enforce-content-type?branch=master)
[](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'
}))
```