express icon indicating copy to clipboard operation
express copied to clipboard

Enhance `req.acceptsEncodings` Method `5.x`

Open Abdel-Monaam-Aouini opened this issue 5 months ago • 0 comments

Enhance req.acceptsEncodings Method

This enhancement refines the req.acceptsEncodings method to improve the handling of the request's Accept-Encoding header. The updated method checks whether the client accepts the specified encoding(s) and returns the best matching encoding or an array of acceptable encodings.

Key Features:

  • Supports single or multiple encoding strings and a comma-delimited list of encodings.
  • Provides consistent behavior across different input formats.
  • Enhances code readability and maintainability.

Examples:

  • req.acceptsEncodings('gzip') returns "gzip" when the Accept-Encoding header includes "gzip".
  • req.acceptsEncodings('br') returns undefined if the encoding isn't accepted by the client.
  • req.acceptsEncodings('gzip, deflate') returns "gzip" as the best match.

This update ensures more robust handling of accepted encodings, improving compatibility and performance.

Abdel-Monaam-Aouini avatar Aug 28 '24 10:08 Abdel-Monaam-Aouini