Skip to content

Commit

Permalink
Replace accepts with negotiator
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeembrey committed Oct 24, 2024
1 parent 5e6ee06 commit 1e95836
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
11 changes: 3 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @private
*/

var accepts = require('accepts')
var Negotiator = require('negotiator')
var Buffer = require('safe-buffer').Buffer
var bytes = require('bytes')
var compressible = require('compressible')
Expand Down Expand Up @@ -174,13 +174,8 @@ function compression (options) {
}

// compression method
var accept = accepts(req)
var method = accept.encoding(['gzip', 'deflate', 'identity'])

// we really don't prefer deflate
if (method === 'deflate' && accept.encoding(['gzip'])) {
method = accept.encoding(['gzip', 'identity'])
}
var negotiator = new Negotiator(req)
var method = negotiator.encoding(['gzip', 'deflate', 'identity'], ['gzip'])

// negotiation failed
if (!method || method === 'identity') {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
"license": "MIT",
"repository": "expressjs/compression",
"dependencies": {
"accepts": "~1.3.8",
"bytes": "3.1.2",
"compressible": "~2.0.18",
"debug": "2.6.9",
"negotiator": "~0.6.4",
"on-headers": "~1.0.2",
"safe-buffer": "5.2.1",
"vary": "~1.1.2"
Expand Down

0 comments on commit 1e95836

Please sign in to comment.