diff --git a/lib/request.js b/lib/request.js index 372a9915e9..a505a60c5d 100644 --- a/lib/request.js +++ b/lib/request.js @@ -134,16 +134,37 @@ req.accepts = function(){ }; /** - * Check if the given `encoding`s are accepted. + * Checks if the specified encodings are accepted based on the request's `Accept-Encoding` header. + * Returns the best matching encoding or an array of acceptable encodings. * - * @param {String} ...encoding - * @return {String|Array} + * The `encoding` argument(s) can be: + * - A single encoding string (e.g., "gzip") + * - Multiple encoding strings as arguments (e.g., `"gzip", "deflate"`) + * - A comma-delimited list of encodings (e.g., `"gzip, deflate"`) + * + * Examples: + * + * // Accept-Encoding: gzip, deflate + * req.acceptsEncodings('gzip'); + * // => "gzip" + * + * req.acceptsEncodings('gzip', 'deflate'); + * // => "gzip" + * + * req.acceptsEncodings('br'); + * // => undefined + * + * req.acceptsEncodings('gzip, br'); + * // => "gzip" + * + * @param {...String} encodings - The encoding(s) to check against the `Accept-Encoding` header. + * @return {String|Array} - The best matching encoding, or an array of acceptable encodings. * @public */ -req.acceptsEncodings = function(){ - var accept = accepts(this); - return accept.encodings.apply(accept, arguments); +req.acceptsEncodings = function(...encodings) { + const accept = accepts(this); + return accept.encodings(...encodings); }; /**