req.accepts()
Return whether this request (req
) advertises that it understands the specified media type.
If none of the media types are considered acceptable, this returns
false
. Otherwise, it returns truthy (the media type).
req.accepts(mediaType);
If a request is sent with an "Accept: application/json"
header:
req.accepts('application/json');
// -> 'application/json'
req.accepts('json');
// -> 'json'
req.accepts('image/png');
// -> false
If a request is sent with an "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"
header:
req.accepts('html');
// -> 'html'
req.accepts('text/html');
// -> 'text/html'
req.accepts('json');
// -> false
- The specified media type may be provided as either a MIME type string such as "application/json", or an extension name such as "json".
- This is implemented by examining the request's "Accept" header.
- See the
accepts
package for the finer details of the header-parsing algorithm used in Sails/Express.