Skip to content

Commit

Permalink
fix: Enhance req.acceptsEncodings
Browse files Browse the repository at this point in the history
  • Loading branch information
Monaam Aouini committed Oct 25, 2024
1 parent 8cb53ea commit 8cda4f1
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

/**
Expand Down

0 comments on commit 8cda4f1

Please sign in to comment.