@fastify/compress 8.0.0-pre.fv5.2 → 8.0.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/.c8rc +14 -0
- package/index.js +5 -5
- package/package.json +8 -8
- package/test/global-compress.test.js +493 -492
- package/test/global-decompress.test.js +70 -60
- package/test/regression/issue-288.test.js +4 -4
- package/test/routes-compress.test.js +80 -72
- package/test/routes-decompress.test.js +45 -41
- package/test/utils.test.js +52 -48
- package/.taprc +0 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const { test } = require('
|
|
3
|
+
const { test, describe } = require('node:test')
|
|
4
4
|
const { createReadStream } = require('node:fs')
|
|
5
5
|
const path = require('node:path')
|
|
6
6
|
const zlib = require('node:zlib')
|
|
@@ -18,9 +18,10 @@ function createPayload (compressor) {
|
|
|
18
18
|
return payload
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
describe('When using routes `decompress` settings :', async (suite) => {
|
|
22
|
+
test('it should decompress data using the route custom provided `createInflate` method', async (t) => {
|
|
23
23
|
t.plan(8)
|
|
24
|
+
const equal = t.assert.equal
|
|
24
25
|
|
|
25
26
|
let usedCustomGlobal = false
|
|
26
27
|
let usedCustom = false
|
|
@@ -51,11 +52,11 @@ test('When using routes `decompress` settings :', async (t) => {
|
|
|
51
52
|
},
|
|
52
53
|
payload: createPayload(zlib.createDeflate)
|
|
53
54
|
}).then((response) => {
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
equal(usedCustom, false)
|
|
56
|
+
equal(usedCustomGlobal, true)
|
|
56
57
|
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
equal(response.statusCode, 200)
|
|
59
|
+
equal(response.body, '@fastify/compress')
|
|
59
60
|
|
|
60
61
|
usedCustom = false
|
|
61
62
|
usedCustomGlobal = false
|
|
@@ -69,15 +70,16 @@ test('When using routes `decompress` settings :', async (t) => {
|
|
|
69
70
|
},
|
|
70
71
|
payload: createPayload(zlib.createDeflate)
|
|
71
72
|
})
|
|
72
|
-
|
|
73
|
-
|
|
73
|
+
equal(usedCustom, true)
|
|
74
|
+
equal(usedCustomGlobal, false)
|
|
74
75
|
|
|
75
|
-
|
|
76
|
-
|
|
76
|
+
equal(response.statusCode, 200)
|
|
77
|
+
equal(response.body, '@fastify/compress')
|
|
77
78
|
})
|
|
78
79
|
|
|
79
|
-
|
|
80
|
+
test('it should decompress data using the route custom provided `createGunzip` method', async (t) => {
|
|
80
81
|
t.plan(8)
|
|
82
|
+
const equal = t.assert.equal
|
|
81
83
|
|
|
82
84
|
let usedCustomGlobal = false
|
|
83
85
|
let usedCustom = false
|
|
@@ -108,11 +110,11 @@ test('When using routes `decompress` settings :', async (t) => {
|
|
|
108
110
|
},
|
|
109
111
|
payload: createPayload(zlib.createGzip)
|
|
110
112
|
}).then((response) => {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
+
equal(usedCustom, false)
|
|
114
|
+
equal(usedCustomGlobal, true)
|
|
113
115
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
+
equal(response.statusCode, 200)
|
|
117
|
+
equal(response.body, '@fastify/compress')
|
|
116
118
|
|
|
117
119
|
usedCustom = false
|
|
118
120
|
usedCustomGlobal = false
|
|
@@ -127,15 +129,16 @@ test('When using routes `decompress` settings :', async (t) => {
|
|
|
127
129
|
},
|
|
128
130
|
payload: createPayload(zlib.createGzip)
|
|
129
131
|
})
|
|
130
|
-
|
|
131
|
-
|
|
132
|
+
equal(usedCustom, true)
|
|
133
|
+
equal(usedCustomGlobal, false)
|
|
132
134
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
+
equal(response.statusCode, 200)
|
|
136
|
+
equal(response.body, '@fastify/compress')
|
|
135
137
|
})
|
|
136
138
|
|
|
137
|
-
|
|
139
|
+
test('it should not decompress data when route `decompress` option is set to `false`', async (t) => {
|
|
138
140
|
t.plan(6)
|
|
141
|
+
const equal = t.assert.equal
|
|
139
142
|
|
|
140
143
|
let usedCustomGlobal = false
|
|
141
144
|
const customZlibGlobal = { createGunzip: () => (usedCustomGlobal = true) && zlib.createGunzip() }
|
|
@@ -160,10 +163,10 @@ test('When using routes `decompress` settings :', async (t) => {
|
|
|
160
163
|
},
|
|
161
164
|
payload: createPayload(zlib.createGzip)
|
|
162
165
|
}).then((response) => {
|
|
163
|
-
|
|
166
|
+
equal(usedCustomGlobal, true)
|
|
164
167
|
|
|
165
|
-
|
|
166
|
-
|
|
168
|
+
equal(response.statusCode, 200)
|
|
169
|
+
equal(response.body, '@fastify/compress')
|
|
167
170
|
|
|
168
171
|
usedCustomGlobal = false
|
|
169
172
|
})
|
|
@@ -177,10 +180,10 @@ test('When using routes `decompress` settings :', async (t) => {
|
|
|
177
180
|
},
|
|
178
181
|
payload: createPayload(zlib.createGzip)
|
|
179
182
|
})
|
|
180
|
-
|
|
183
|
+
equal(usedCustomGlobal, false)
|
|
181
184
|
|
|
182
|
-
|
|
183
|
-
t.
|
|
185
|
+
equal(response.statusCode, 400)
|
|
186
|
+
t.assert.deepEqual(response.json(), {
|
|
184
187
|
statusCode: 400,
|
|
185
188
|
code: 'FST_ERR_CTP_INVALID_CONTENT_LENGTH',
|
|
186
189
|
error: 'Bad Request',
|
|
@@ -188,7 +191,7 @@ test('When using routes `decompress` settings :', async (t) => {
|
|
|
188
191
|
})
|
|
189
192
|
})
|
|
190
193
|
|
|
191
|
-
|
|
194
|
+
test('it should throw an error on invalid route `decompress` settings', async (t) => {
|
|
192
195
|
t.plan(1)
|
|
193
196
|
|
|
194
197
|
const fastify = Fastify()
|
|
@@ -199,14 +202,15 @@ test('When using routes `decompress` settings :', async (t) => {
|
|
|
199
202
|
reply.send(request.body.name)
|
|
200
203
|
})
|
|
201
204
|
} catch (err) {
|
|
202
|
-
t.equal(err.message, 'Unknown value for route decompress configuration')
|
|
205
|
+
t.assert.equal(err.message, 'Unknown value for route decompress configuration')
|
|
203
206
|
}
|
|
204
207
|
})
|
|
205
208
|
})
|
|
206
209
|
|
|
207
|
-
|
|
208
|
-
|
|
210
|
+
describe('When using the old routes `{ config: decompress }` option :', async () => {
|
|
211
|
+
test('it should decompress data using the route custom provided `createGunzip` method', async (t) => {
|
|
209
212
|
t.plan(8)
|
|
213
|
+
const equal = t.assert.equal
|
|
210
214
|
|
|
211
215
|
let usedCustomGlobal = false
|
|
212
216
|
let usedCustom = false
|
|
@@ -239,11 +243,11 @@ test('When using the old routes `{ config: decompress }` option :', async (t) =>
|
|
|
239
243
|
},
|
|
240
244
|
payload: createPayload(zlib.createGzip)
|
|
241
245
|
}).then((response) => {
|
|
242
|
-
|
|
243
|
-
|
|
246
|
+
equal(usedCustom, false)
|
|
247
|
+
equal(usedCustomGlobal, true)
|
|
244
248
|
|
|
245
|
-
|
|
246
|
-
|
|
249
|
+
equal(response.statusCode, 200)
|
|
250
|
+
equal(response.body, '@fastify/compress')
|
|
247
251
|
|
|
248
252
|
usedCustom = false
|
|
249
253
|
usedCustomGlobal = false
|
|
@@ -258,14 +262,14 @@ test('When using the old routes `{ config: decompress }` option :', async (t) =>
|
|
|
258
262
|
},
|
|
259
263
|
payload: createPayload(zlib.createGzip)
|
|
260
264
|
})
|
|
261
|
-
|
|
262
|
-
|
|
265
|
+
equal(usedCustom, true)
|
|
266
|
+
equal(usedCustomGlobal, false)
|
|
263
267
|
|
|
264
|
-
|
|
265
|
-
|
|
268
|
+
equal(response.statusCode, 200)
|
|
269
|
+
equal(response.body, '@fastify/compress')
|
|
266
270
|
})
|
|
267
271
|
|
|
268
|
-
|
|
272
|
+
test('it should use the old routes `{ config: decompress }` options over routes `decompress` options', async (t) => {
|
|
269
273
|
t.plan(1)
|
|
270
274
|
|
|
271
275
|
const fastify = Fastify()
|
|
@@ -283,7 +287,7 @@ test('When using the old routes `{ config: decompress }` option :', async (t) =>
|
|
|
283
287
|
reply.send(request.body.name)
|
|
284
288
|
})
|
|
285
289
|
} catch (err) {
|
|
286
|
-
t.equal(err.message, 'Unknown value for route decompress configuration')
|
|
290
|
+
t.assert.equal(err.message, 'Unknown value for route decompress configuration')
|
|
287
291
|
}
|
|
288
292
|
})
|
|
289
293
|
})
|
package/test/utils.test.js
CHANGED
|
@@ -3,67 +3,71 @@
|
|
|
3
3
|
const { createReadStream } = require('node:fs')
|
|
4
4
|
const { Socket } = require('node:net')
|
|
5
5
|
const { Duplex, PassThrough, Readable, Stream, Transform, Writable } = require('node:stream')
|
|
6
|
-
const { test } = require('
|
|
6
|
+
const { test } = require('node:test')
|
|
7
7
|
const { isStream, isDeflate, isGzip, intoAsyncIterator } = require('../lib/utils')
|
|
8
8
|
|
|
9
9
|
test('isStream() utility should be able to detect Streams', async (t) => {
|
|
10
10
|
t.plan(12)
|
|
11
|
+
const equal = t.assert.equal
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
equal(isStream(new Stream()), true)
|
|
14
|
+
equal(isStream(new Readable()), true)
|
|
15
|
+
equal(isStream(new Writable()), true)
|
|
16
|
+
equal(isStream(new Duplex()), true)
|
|
17
|
+
equal(isStream(new Transform()), true)
|
|
18
|
+
equal(isStream(new PassThrough()), true)
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
equal(isStream(createReadStream('package.json')), true)
|
|
20
21
|
|
|
21
|
-
|
|
22
|
+
equal(isStream(new Socket()), true)
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
equal(isStream({}), false)
|
|
25
|
+
equal(isStream(null), false)
|
|
26
|
+
equal(isStream(undefined), false)
|
|
27
|
+
equal(isStream(''), false)
|
|
27
28
|
})
|
|
28
29
|
|
|
29
30
|
test('isDeflate() utility should be able to detect deflate compressed Buffer', async (t) => {
|
|
30
31
|
t.plan(14)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
32
|
+
const equal = t.assert.equal
|
|
33
|
+
|
|
34
|
+
equal(isDeflate(Buffer.alloc(0)), false)
|
|
35
|
+
equal(isDeflate(Buffer.alloc(0)), false)
|
|
36
|
+
equal(isDeflate(Buffer.from([0x78])), false)
|
|
37
|
+
equal(isDeflate(Buffer.from([0x78, 0x00])), false)
|
|
38
|
+
equal(isDeflate(Buffer.from([0x7a, 0x01])), false)
|
|
39
|
+
equal(isDeflate(Buffer.from([0x88, 0x01])), false)
|
|
40
|
+
equal(isDeflate(Buffer.from([0x78, 0x11])), false)
|
|
41
|
+
equal(isDeflate(Buffer.from([0x78, 0x01])), true)
|
|
42
|
+
equal(isDeflate(Buffer.from([0x78, 0x9c])), true)
|
|
43
|
+
equal(isDeflate(Buffer.from([0x78, 0xda])), true)
|
|
44
|
+
|
|
45
|
+
equal(isDeflate({}), false)
|
|
46
|
+
equal(isDeflate(null), false)
|
|
47
|
+
equal(isDeflate(undefined), false)
|
|
48
|
+
equal(isDeflate(''), false)
|
|
47
49
|
})
|
|
48
50
|
|
|
49
51
|
test('isGzip() utility should be able to detect gzip compressed Buffer', async (t) => {
|
|
50
52
|
t.plan(10)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
53
|
+
const equal = t.assert.equal
|
|
54
|
+
|
|
55
|
+
equal(isGzip(Buffer.alloc(0)), false)
|
|
56
|
+
equal(isGzip(Buffer.alloc(1)), false)
|
|
57
|
+
equal(isGzip(Buffer.alloc(2)), false)
|
|
58
|
+
equal(isGzip(Buffer.from([0x1f, 0x8b])), false)
|
|
59
|
+
equal(isGzip(Buffer.from([0x1f, 0x8b, 0x00])), false)
|
|
60
|
+
equal(isGzip(Buffer.from([0x1f, 0x8b, 0x08])), true)
|
|
61
|
+
|
|
62
|
+
equal(isGzip({}), false)
|
|
63
|
+
equal(isGzip(null), false)
|
|
64
|
+
equal(isGzip(undefined), false)
|
|
65
|
+
equal(isGzip(''), false)
|
|
63
66
|
})
|
|
64
67
|
|
|
65
68
|
test('intoAsyncIterator() utility should handle different data', async (t) => {
|
|
66
69
|
t.plan(8)
|
|
70
|
+
const equal = t.assert.equal
|
|
67
71
|
|
|
68
72
|
const buf = Buffer.from('foo')
|
|
69
73
|
const str = 'foo'
|
|
@@ -76,30 +80,30 @@ test('intoAsyncIterator() utility should handle different data', async (t) => {
|
|
|
76
80
|
const obj = {}
|
|
77
81
|
|
|
78
82
|
for await (const buffer of intoAsyncIterator(buf)) {
|
|
79
|
-
|
|
83
|
+
equal(buffer, buf)
|
|
80
84
|
}
|
|
81
85
|
|
|
82
86
|
for await (const string of intoAsyncIterator(str)) {
|
|
83
|
-
|
|
87
|
+
equal(string, str)
|
|
84
88
|
}
|
|
85
89
|
|
|
86
90
|
for await (const chunk of intoAsyncIterator(arr)) {
|
|
87
|
-
|
|
91
|
+
equal(chunk, str)
|
|
88
92
|
}
|
|
89
93
|
|
|
90
94
|
for await (const chunk of intoAsyncIterator(arrayBuffer)) {
|
|
91
|
-
|
|
95
|
+
equal(chunk.toString(), Buffer.from(arrayBuffer).toString())
|
|
92
96
|
}
|
|
93
97
|
|
|
94
98
|
for await (const chunk of intoAsyncIterator(typedArray)) {
|
|
95
|
-
|
|
99
|
+
equal(chunk.toString(), Buffer.from(typedArray).toString())
|
|
96
100
|
}
|
|
97
101
|
|
|
98
102
|
for await (const chunk of intoAsyncIterator(asyncIterator)) {
|
|
99
|
-
|
|
103
|
+
equal(chunk, str)
|
|
100
104
|
}
|
|
101
105
|
|
|
102
106
|
for await (const chunk of intoAsyncIterator(obj)) {
|
|
103
|
-
|
|
107
|
+
equal(chunk, obj)
|
|
104
108
|
}
|
|
105
109
|
})
|
package/.taprc
DELETED