Skip to content

Commit

Permalink
improve negotiateEnconding
Browse files Browse the repository at this point in the history
  • Loading branch information
bjohansebas committed Oct 24, 2024
1 parent 3d30ab0 commit 662c09d
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions encoding_negotiator.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,10 @@ var Negotiator = require('negotiator')
*/
var hasBrotliSupport = 'createBrotliCompress' in zlib

function negotiateEncoding (req, encodings_) {
function negotiateEncoding (req, encodings) {
var negotiator = new Negotiator(req)
var encodings = encodings_

// support flattened arguments
if (encodings && !Array.isArray(encodings)) {
encodings = new Array(arguments.length)
for (var i = 0; i < encodings.length; i++) {
encodings[i] = arguments[i]
}
}

// no encodings, return all requested encodings
if (!encodings || encodings.length === 0) {
return negotiator.encodings()
}

return negotiator.encodings(encodings, hasBrotliSupport ? ['br'] : ['gzip'])[0] || false
return negotiator.encodings(encodings, hasBrotliSupport ? ['br'] : ['gzip'])[0]
}

module.exports.hasBrotliSupport = hasBrotliSupport
Expand Down

0 comments on commit 662c09d

Please sign in to comment.