Skip to content
Myr

fix: enhance req.acceptsCharsets method (#6088)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* fix: enhance req.acceptsCharsets method * Update req.acceptsCharsets.js ---------

authored by AbdelMonaam Aouini · committed by GitHub · parent 3e81873 · Browse files · 2 files+37 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: Monaam Aouini <abdelmonaem.aouini@mispay.co>
  • Co-authored-by: Sebastian Beltran <bjohansebas@gmail.com>

Diff stats

2 files+37 added−7 removed

  • tests:+13 added−0 removed
  • other:+24 added−7 removed

2 files+37 added−7 removed

modified:lib/request.js+24 added-7 removed
145 unmodified lines
146 return accept.encodings.apply(accept, arguments);147};148149/**150 * Check if the given `charset`s are acceptable,151 * otherwise you should respond with 406 "Not Acceptable".150 * Checks if the specified `charset`s are acceptable based on the request's `Accept-Charset` header.151 * Returns the best matching charset or an array of acceptable charsets.152 *153 * @param {String} ...charset154 * @return {String|Array}153 * The `charset` argument(s) can be:154 * - A single charset string (e.g., "utf-8")155 * - Multiple charset strings as arguments (e.g., `"utf-8", "iso-8859-1"`)156 * - A comma-delimited list of charsets (e.g., `"utf-8, iso-8859-1"`)157 *158 * Examples:159 *160 * // Accept-Charset: utf-8, iso-8859-1161 * req.acceptsCharsets('utf-8');162 * // => "utf-8"163 *164 * req.acceptsCharsets('utf-8', 'iso-8859-1');165 * // => "utf-8"166 *167 * req.acceptsCharsets('utf-8, utf-16');168 * // => "utf-8"169 *170 * @param {...String} charsets - The charset(s) to check against the `Accept-Charset` header.171 * @return {String|Array} - The best matching charset, or an array of acceptable charsets.172 * @public173 */174158req.acceptsCharsets = function(){159 var accept = accepts(this);160 return accept.charsets.apply(accept, arguments);175req.acceptsCharsets = function(...charsets) {176 const accept = accepts(this);177 return accept.charsets(...charsets);178};179180/**181 * Check if the given `lang`s are acceptable,
350 unmodified lines
modified:test/req.acceptsCharsets.js+13 added