1. Html Content Type Header
  2. Content Type Header Request

Jul 27, 2016 - You can find every content type here: The most common type are: Type application.

Create and parse HTTP Content-Type header according to RFC 7231

Installation

Html Content Type Header

API

contentType.parse(string)

Content Type Header Request

Parse a Content-Type header. This will return an object with the followingproperties (examples are shown for the string 'image/svg+xml; charset=utf-8'):

  • type: The media type (the type and subtype, always lower case).Example: 'image/svg+xml'

  • parameters: An object of the parameters in the media type (name of parameteralways lower case). Example: {charset: 'utf-8'}

Throws a TypeError if the string is missing or invalid.

contentType.parse(req)

Parse the Content-Type header from the given req. Short-cut forcontentType.parse(req.headers['content-type']).

Throws a TypeError if the Content-Type header is missing or invalid.

contentType.parse(res)

Content Type Header

Parse the Content-Type header set on the given res. Short-cut forcontentType.parse(res.getHeader('content-type')).

Throws a TypeError if the Content-Type header is missing or invalid.

contentType.format(obj)

Format an object into a Content-Type header. This will return a string of thecontent type for the given object with the following properties (examples areshown that produce the string 'image/svg+xml; charset=utf-8'):

  • type: The media type (will be lower-cased). Example: 'image/svg+xml'

  • parameters: An object of the parameters in the media type (name of theparameter will be lower-cased). Example: {charset: 'utf-8'}

Throws a TypeError if the object contains an invalid type or parameter names.

License