Skip to content

Commit bd24382

Browse files
authored
fix: replace content encoding negotiation and fix Brotli compression
2 parents ca2f4d9 + f5e8143 commit bd24382

File tree

4 files changed

+30
-55
lines changed

4 files changed

+30
-55
lines changed

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*

index.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
* Module dependencies.
1414
* @private
1515
*/
16-
17-
var accepts = require('accepts')
16+
var accept = require('accept')
1817
var Buffer = require('safe-buffer').Buffer
1918
var bytes = require('bytes')
2019
var compressible = require('compressible')
@@ -174,19 +173,19 @@ function compression (options) {
174173
}
175174

176175
// compression method
177-
var accept = accepts(req)
178176
var methods = ['gzip', 'deflate', 'identity']
179177
var preferredMethods = ['gzip']
178+
var acceptEncodingHeader = req.header('accept-encoding')
180179

181-
if (zlib.createBrotliDecompress) {
180+
if (zlib.createBrotliCompress) {
182181
methods.unshift('br')
183182
preferredMethods.unshift('br')
184183
}
185184

186-
var method = accept.encoding(methods)
185+
var method = accept.encoding(acceptEncodingHeader, methods)
187186

188187
// we really don't prefer deflate
189-
if (method === 'deflate' && accept.encoding(preferredMethods)) {
188+
if (method === 'deflate' && accept.encoding(acceptEncodingHeader, preferredMethods)) {
190189
preferredMethods.push('identity')
191190
method = accept.encoding(preferredMethods)
192191
}
@@ -200,7 +199,7 @@ function compression (options) {
200199
// compression stream
201200
debug('%s compression', method)
202201
switch (method) {
203-
case 'br': stream = zlib.createBrotliDecompress(opts); break
202+
case 'br': stream = zlib.createBrotliCompress(opts); break
204203
case 'gzip': stream = zlib.createGzip(opts); break
205204
case 'deflate': stream = zlib.createDeflate(opts); break
206205
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"license": "MIT",
1010
"repository": "deal/compression",
1111
"dependencies": {
12-
"accepts": "~1.3.5",
12+
"accept": "^3.1.3",
1313
"bytes": "3.0.0",
1414
"compressible": "~2.0.14",
1515
"debug": "2.6.9",

yarn.lock

Lines changed: 22 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,13 @@ abbrev@1.0.x:
140140
resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.0.9.tgz#91b4792588a7738c25f35dd6f63752a2f8776135"
141141
integrity sha1-kbR5JYinc4wl813W9jdSovh3YTU=
142142

143-
accepts@~1.3.5:
144-
version "1.3.5"
145-
resolved "https://registry.yarnpkg.com/accepts/-/accepts-1.3.5.tgz#eb777df6011723a3b14e8a72c0805c8e86746bd2"
146-
integrity sha1-63d99gEXI6OxTopywIBcjoZ0a9I=
143+
accept@^3.1.3:
144+
version "3.1.3"
145+
resolved "https://registry.yarnpkg.com/accept/-/accept-3.1.3.tgz#29c3e2b3a8f4eedbc2b690e472b9ebbdc7385e87"
146+
integrity sha512-OgOEAidVEOKPup+Gv2+2wdH2AgVKI9LxsJ4hicdJ6cY0faUuZdZoi56kkXWlHp9qicN1nWQLmW5ZRGk+SBS5xg==
147147
dependencies:
148-
mime-types "~2.1.18"
149-
negotiator "0.6.1"
148+
boom "7.x.x"
149+
hoek "6.x.x"
150150

151151
acorn-jsx@^3.0.0:
152152
version "3.0.1"
@@ -479,6 +479,13 @@ bluebird@^3.5.0, bluebird@^3.5.1, bluebird@^3.5.3:
479479
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.3.tgz#7d01c6f9616c9a51ab0f8c549a79dfe6ec33efa7"
480480
integrity sha512-/qKPUQlaW1OyR51WeCPBvRnAlnZFUJkCSG5HzGnuIqhgyJtF+T94lFnn33eiazjRm2LAHVy2guNnaq48X9SJuw==
481481

482+
boom@7.x.x:
483+
version "7.3.0"
484+
resolved "https://registry.yarnpkg.com/boom/-/boom-7.3.0.tgz#733a6d956d33b0b1999da3fe6c12996950d017b9"
485+
integrity sha512-Swpoyi2t5+GhOEGw8rEsKvTxFLIDiiKoUc2gsoV6Lyr43LHBIzch3k2MvYUs8RTROrIkVJ3Al0TkaOGjnb+B6A==
486+
dependencies:
487+
hoek "6.x.x"
488+
482489
bottleneck@^2.0.1:
483490
version "2.17.0"
484491
resolved "https://registry.yarnpkg.com/bottleneck/-/bottleneck-2.17.0.tgz#4654c78ea6333bf41a77faa4b4909a57f05c2ac3"
@@ -1160,7 +1167,7 @@ debug@^4.0.0:
11601167
dependencies:
11611168
ms "^2.1.1"
11621169

1163-
debuglog@*, debuglog@^1.0.1:
1170+
debuglog@^1.0.1:
11641171
version "1.0.1"
11651172
resolved "https://registry.yarnpkg.com/debuglog/-/debuglog-1.0.1.tgz#aa24ffb9ac3df9a2351837cfb2d279360cd78492"
11661173
integrity sha1-qiT/uaw9+aI1GDfPstJ5NgzXhJI=
@@ -2178,6 +2185,11 @@ has@^1.0.1:
21782185
dependencies:
21792186
function-bind "^1.1.1"
21802187

2188+
hoek@6.x.x:
2189+
version "6.1.2"
2190+
resolved "https://registry.yarnpkg.com/hoek/-/hoek-6.1.2.tgz#99e6d070561839de74ee427b61aa476bd6bddfd6"
2191+
integrity sha512-6qhh/wahGYZHFSFw12tBbJw5fsAhhwrrG/y3Cs0YMTv2WzMnL0oLPnQJjv1QJvEfylRSOFuP+xCu+tdx0tD16Q==
2192+
21812193
hook-std@^1.1.0:
21822194
version "1.2.0"
21832195
resolved "https://registry.yarnpkg.com/hook-std/-/hook-std-1.2.0.tgz#b37d533ea5f40068fe368cb4d022ee1992588c27"
@@ -2279,7 +2291,7 @@ import-lazy@^2.1.0:
22792291
resolved "https://registry.yarnpkg.com/import-lazy/-/import-lazy-2.1.0.tgz#05698e3d45c88e8d7e9d92cb0584e77f096f3e43"
22802292
integrity sha1-BWmOPUXIjo1+nZLLBYTnfwlvPkM=
22812293

2282-
imurmurhash@*, imurmurhash@^0.1.4:
2294+
imurmurhash@^0.1.4:
22832295
version "0.1.4"
22842296
resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea"
22852297
integrity sha1-khi5srkoojixPcT7a21XbyMUU+o=
@@ -2915,11 +2927,6 @@ lockfile@^1.0.4:
29152927
dependencies:
29162928
signal-exit "^3.0.2"
29172929

2918-
lodash._baseindexof@*:
2919-
version "3.1.0"
2920-
resolved "https://registry.yarnpkg.com/lodash._baseindexof/-/lodash._baseindexof-3.1.0.tgz#fe52b53a1c6761e42618d654e4a25789ed61822c"
2921-
integrity sha1-/lK1OhxnYeQmGNZU5KJXie1hgiw=
2922-
29232930
lodash._baseuniq@~4.6.0:
29242931
version "4.6.0"
29252932
resolved "https://registry.yarnpkg.com/lodash._baseuniq/-/lodash._baseuniq-4.6.0.tgz#0ebb44e456814af7905c6212fa2c9b2d51b841e8"
@@ -2928,33 +2935,11 @@ lodash._baseuniq@~4.6.0:
29282935
lodash._createset "~4.0.0"
29292936
lodash._root "~3.0.0"
29302937

2931-
lodash._bindcallback@*:
2932-
version "3.0.1"
2933-
resolved "https://registry.yarnpkg.com/lodash._bindcallback/-/lodash._bindcallback-3.0.1.tgz#e531c27644cf8b57a99e17ed95b35c748789392e"
2934-
integrity sha1-5THCdkTPi1epnhftlbNcdIeJOS4=
2935-
2936-
lodash._cacheindexof@*:
2937-
version "3.0.2"
2938-
resolved "https://registry.yarnpkg.com/lodash._cacheindexof/-/lodash._cacheindexof-3.0.2.tgz#3dc69ac82498d2ee5e3ce56091bafd2adc7bde92"
2939-
integrity sha1-PcaayCSY0u5ePOVgkbr9Ktx73pI=
2940-
2941-
lodash._createcache@*:
2942-
version "3.1.2"
2943-
resolved "https://registry.yarnpkg.com/lodash._createcache/-/lodash._createcache-3.1.2.tgz#56d6a064017625e79ebca6b8018e17440bdcf093"
2944-
integrity sha1-VtagZAF2JeeevKa4AY4XRAvc8JM=
2945-
dependencies:
2946-
lodash._getnative "^3.0.0"
2947-
29482938
lodash._createset@~4.0.0:
29492939
version "4.0.3"
29502940
resolved "https://registry.yarnpkg.com/lodash._createset/-/lodash._createset-4.0.3.tgz#0f4659fbb09d75194fa9e2b88a6644d363c9fe26"
29512941
integrity sha1-D0ZZ+7CddRlPqeK4imZE02PJ/iY=
29522942

2953-
lodash._getnative@*, lodash._getnative@^3.0.0:
2954-
version "3.9.1"
2955-
resolved "https://registry.yarnpkg.com/lodash._getnative/-/lodash._getnative-3.9.1.tgz#570bc7dede46d61cdcde687d65d3eecbaa3aaff5"
2956-
integrity sha1-VwvH3t5G1hzc3mh9ZdPuy6o6r/U=
2957-
29582943
lodash._root@~3.0.0:
29592944
version "3.0.1"
29602945
resolved "https://registry.yarnpkg.com/lodash._root/-/lodash._root-3.0.1.tgz#fba1c4524c19ee9a5f8136b4609f017cf4ded692"
@@ -2990,11 +2975,6 @@ lodash.isstring@^4.0.1:
29902975
resolved "https://registry.yarnpkg.com/lodash.isstring/-/lodash.isstring-4.0.1.tgz#d527dfb5456eca7cc9bb95d5daeaf88ba54a5451"
29912976
integrity sha1-1SfftUVuynzJu5XV2ur4i6VKVFE=
29922977

2993-
lodash.restparam@*:
2994-
version "3.6.1"
2995-
resolved "https://registry.yarnpkg.com/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805"
2996-
integrity sha1-k2pOMJ7zMKdkXtQUWYbIWuWyCAU=
2997-
29982978
lodash.set@^4.3.2:
29992979
version "4.3.2"
30002980
resolved "https://registry.yarnpkg.com/lodash.set/-/lodash.set-4.3.2.tgz#d8757b1da807dde24816b0d6a84bea1a76230b23"
@@ -3240,7 +3220,7 @@ mime-db@~1.12.0:
32403220
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.12.0.tgz#3d0c63180f458eb10d325aaa37d7c58ae312e9d7"
32413221
integrity sha1-PQxjGA9FjrENMlqqN9fFiuMS6dc=
32423222

3243-
mime-types@^2.1.12, mime-types@~2.1.18, mime-types@~2.1.19:
3223+
mime-types@^2.1.12, mime-types@~2.1.19:
32443224
version "2.1.22"
32453225
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.22.tgz#fe6b355a190926ab7698c9a0556a11199b2199bd"
32463226
integrity sha512-aGl6TZGnhm/li6F7yx82bJiBZwgiEa4Hf6CNr8YO+r5UHr53tSTYZb102zyU50DOWWKeOv0uQLRL0/9EiKWCog==
@@ -3454,11 +3434,6 @@ natural-compare@^1.4.0:
34543434
resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7"
34553435
integrity sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=
34563436

3457-
negotiator@0.6.1:
3458-
version "0.6.1"
3459-
resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.1.tgz#2b327184e8992101177b28563fb5e7102acd0ca9"
3460-
integrity sha1-KzJxhOiZIQEXeyhWP7XnECrNDKk=
3461-
34623437
nerf-dart@^1.0.0:
34633438
version "1.0.0"
34643439
resolved "https://registry.yarnpkg.com/nerf-dart/-/nerf-dart-1.0.0.tgz#e6dab7febf5ad816ea81cf5c629c5a0ebde72c1a"
@@ -4476,7 +4451,7 @@ readable-stream@~1.1.10:
44764451
isarray "0.0.1"
44774452
string_decoder "~0.10.x"
44784453

4479-
readdir-scoped-modules@*, readdir-scoped-modules@^1.0.0:
4454+
readdir-scoped-modules@^1.0.0:
44804455
version "1.0.2"
44814456
resolved "https://registry.yarnpkg.com/readdir-scoped-modules/-/readdir-scoped-modules-1.0.2.tgz#9fafa37d286be5d92cbaebdee030dc9b5f406747"
44824457
integrity sha1-n6+jfShr5dksuuve4DDcm19AZ0c=

0 commit comments

Comments
 (0)