request.accepts()
Access:
public

This is the accepts class. With this class you can check if the client accepts certain content types, encodings, charsets and/or languages.

Summary

Name
Description
Checks or returns what charsets are accepted.
Checks or returns what encodings are accepted.
Checks or returns what languages are accepted.
Checks or returns what types are accepted.

Functions

.charset(type)
Access:
public
Summary:
Checks or returns what charsets are accepted.

With this function you can get or check what charsets are accepted. If the type parameter is undefined it will return all the accepted charsets. You can also insert an array of charsets and the first item that is accepted will be returned.

Parameters

Name
Type
Description
type
String[]
The array of charsets to check. (optional)

Examples

// with as content-type "utf-8"
req.charset(["ascii", "utf-8", "utf-16"]);
// -> will return "utf-8"

Returns

Type
String[], String
Description
Returns all accept charsets or the type that matched.
.encoding(type)
Access:
public
Summary:
Checks or returns what encodings are accepted.

With this function you can get or check what encodings are accepted. If the type parameter is undefined it will return all the accepted encodings. You can also insert an array of encodings and the first item that is accepted will be returned.

Parameters

Name
Type
Description
type
String[]
The array of encodings to check. (optional)

Examples

// with as content-type "deflate"
req.charset(["utf-8", "deflate", "gzip"]);
// -> will return "deflate"

Returns

Type
String[], String
Description
Returns all accept encodings or the type that matched.
.language(type)
Access:
public
Summary:
Checks or returns what languages are accepted.

With this function you can get or check what languages are accepted. If the type parameter is undefined it will return all the accepted languages. You can also insert an array of languages and the first item that is accepted will be returned.

Parameters

Name
Type
Description
type
String[]
The array of languages to check. (optional)

Examples

// with as content-type "en"
req.charset(["nl", "en", "de"]);
// -> will return "en"

Returns

Type
String[], String
Description
Returns all accept languages or the type that matched.
.type(type)
Access:
public
Summary:
Checks or returns what types are accepted.

With this function you can get or check what types are accepted. If the type parameter is undefined it will return all the accepted types. You can also insert an array of types and the first item that is accepted will be returned.

Parameters

Name
Type
Description
type
String[]
The array of types to check. (optional)

Examples

// with as content-type "application/javascript"
req.charset(["css", "js", "html"]);
// -> will return "application/javascript"

Returns

Type
String[], String
Description
Returns all accept types or the type that matched.