Skip to content

Connect/Express middleware to enforce Content-Type headers on request

License

Notifications You must be signed in to change notification settings

codepunkt/enforce-content-type

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Enforce Content-Type middleware

npm version Build Status Coverage Status js-standard-style

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.

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

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

It is also possible to specify multiple acceptable content types:

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

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

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

About

Connect/Express middleware to enforce Content-Type headers on request

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published