@fastify/compress 6.2.0 → 6.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +2 -2
- package/package.json +4 -4
- package/test/global-compress.test.js +30 -1
package/index.js
CHANGED
|
@@ -142,7 +142,7 @@ function processCompressParams (opts) {
|
|
|
142
142
|
params.encodings = Array.isArray(opts.encodings)
|
|
143
143
|
? supportedEncodings
|
|
144
144
|
.filter(encoding => opts.encodings.includes(encoding))
|
|
145
|
-
.sort((a, b) => opts.encodings.indexOf(a) -
|
|
145
|
+
.sort((a, b) => opts.encodings.indexOf(a) - opts.encodings.indexOf(b))
|
|
146
146
|
: supportedEncodings
|
|
147
147
|
|
|
148
148
|
return params
|
|
@@ -174,7 +174,7 @@ function processDecompressParams (opts) {
|
|
|
174
174
|
params.encodings = Array.isArray(opts.requestEncodings)
|
|
175
175
|
? supportedEncodings
|
|
176
176
|
.filter(encoding => opts.requestEncodings.includes(encoding))
|
|
177
|
-
.sort((a, b) => opts.requestEncodings.indexOf(a) -
|
|
177
|
+
.sort((a, b) => opts.requestEncodings.indexOf(a) - opts.requestEncodings.indexOf(b))
|
|
178
178
|
: supportedEncodings
|
|
179
179
|
|
|
180
180
|
if (opts.forceRequestEncoding) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fastify/compress",
|
|
3
|
-
"version": "6.2.
|
|
3
|
+
"version": "6.2.1",
|
|
4
4
|
"description": "Fastify compression utils",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"fastify-plugin": "^4.0.0",
|
|
10
10
|
"into-stream": "^6.0.0",
|
|
11
11
|
"mime-db": "^1.51.0",
|
|
12
|
-
"minipass": "^
|
|
12
|
+
"minipass": "^4.0.0",
|
|
13
13
|
"peek-stream": "^1.1.3",
|
|
14
14
|
"pump": "^3.0.0",
|
|
15
15
|
"pumpify": "^2.0.1"
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"jsonstream": "^1.0.3",
|
|
25
25
|
"standard": "^17.0.0",
|
|
26
26
|
"tap": "^16.0.0",
|
|
27
|
-
"tsd": "^0.
|
|
28
|
-
"typescript": "^
|
|
27
|
+
"tsd": "^0.28.0",
|
|
28
|
+
"typescript": "^5.0.2"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
31
|
"coverage": "npm run unit -- --cov",
|
|
@@ -2703,7 +2703,7 @@ test('It should sort and follow custom `encodings` options', async (t) => {
|
|
|
2703
2703
|
const fastify = Fastify()
|
|
2704
2704
|
await fastify.register(compressPlugin, {
|
|
2705
2705
|
global: true,
|
|
2706
|
-
encodings: ['
|
|
2706
|
+
encodings: ['br', 'gzip']
|
|
2707
2707
|
})
|
|
2708
2708
|
|
|
2709
2709
|
fastify.get('/', (request, reply) => {
|
|
@@ -2725,6 +2725,35 @@ test('It should sort and follow custom `encodings` options', async (t) => {
|
|
|
2725
2725
|
t.equal(payload.toString('utf-8'), file)
|
|
2726
2726
|
})
|
|
2727
2727
|
|
|
2728
|
+
test('It should sort and prefer the order of custom `encodings` options', async (t) => {
|
|
2729
|
+
t.plan(2)
|
|
2730
|
+
|
|
2731
|
+
const fastify = Fastify()
|
|
2732
|
+
await fastify.register(compressPlugin, {
|
|
2733
|
+
global: true,
|
|
2734
|
+
encodings: ['gzip', 'deflate', 'br']
|
|
2735
|
+
})
|
|
2736
|
+
|
|
2737
|
+
fastify.get('/', (request, reply) => {
|
|
2738
|
+
reply
|
|
2739
|
+
.type('text/plain')
|
|
2740
|
+
.compress(createReadStream('./package.json'))
|
|
2741
|
+
})
|
|
2742
|
+
|
|
2743
|
+
const response = await fastify.inject({
|
|
2744
|
+
url: '/',
|
|
2745
|
+
method: 'GET',
|
|
2746
|
+
headers: {
|
|
2747
|
+
'accept-encoding': 'hello,gzip,br'
|
|
2748
|
+
}
|
|
2749
|
+
})
|
|
2750
|
+
|
|
2751
|
+
const file = readFileSync('./package.json', 'utf8')
|
|
2752
|
+
const payload = zlib.gunzipSync(response.rawPayload)
|
|
2753
|
+
t.equal(response.headers['content-encoding'], 'gzip')
|
|
2754
|
+
t.equal(payload.toString('utf-8'), file)
|
|
2755
|
+
})
|
|
2756
|
+
|
|
2728
2757
|
test('It should sort and follow custom `requestEncodings` options', async (t) => {
|
|
2729
2758
|
t.plan(2)
|
|
2730
2759
|
|