Skip to content

Commit

Permalink
perf(compression): use regex exec instead of match (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Jul 27, 2024
1 parent cc89f8e commit 822c80a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/compression/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function ({ threshold = 1024, level = -1, brotli = false, gzip =

return (req, res, next = NOOP) => {
const accept = req.headers['accept-encoding'] + '';
const encoding = ((brotli && accept.match(/\bbr\b/)) || (gzip && accept.match(/\bgzip\b/)) || [])[0];
const encoding = ((brotli && /\bbr\b/.exec(accept)) || (gzip && /\bgzip\b/.exec(accept)) || [])[0];

// skip if no response body or no supported encoding:
if (req.method === 'HEAD' || !encoding) return next();
Expand Down

0 comments on commit 822c80a

Please sign in to comment.