@@ -13,7 +13,7 @@ const compressPlugin = require('./index')
13
13
test ( 'should send a deflated data' , t => {
14
14
t . plan ( 2 )
15
15
const fastify = Fastify ( )
16
- fastify . register ( compressPlugin )
16
+ fastify . register ( compressPlugin , { global : false } )
17
17
18
18
fastify . get ( '/' , ( req , reply ) => {
19
19
reply . type ( 'text/plain' ) . compress ( createReadStream ( './package.json' ) )
@@ -36,7 +36,7 @@ test('should send a deflated data', t => {
36
36
test ( 'should send a gzipped data' , t => {
37
37
t . plan ( 2 )
38
38
const fastify = Fastify ( )
39
- fastify . register ( compressPlugin )
39
+ fastify . register ( compressPlugin , { global : false } )
40
40
41
41
fastify . get ( '/' , ( req , reply ) => {
42
42
reply . type ( 'text/plain' ) . compress ( createReadStream ( './package.json' ) )
@@ -59,7 +59,7 @@ test('should send a gzipped data', t => {
59
59
test ( 'should send a brotli data' , t => {
60
60
t . plan ( 2 )
61
61
const fastify = Fastify ( )
62
- fastify . register ( compressPlugin , { brotli } )
62
+ fastify . register ( compressPlugin , { brotli, global : false } )
63
63
64
64
fastify . get ( '/' , ( req , reply ) => {
65
65
reply . type ( 'text/plain' ) . compress ( createReadStream ( './package.json' ) )
@@ -82,7 +82,7 @@ test('should send a brotli data', t => {
82
82
test ( 'should follow the encoding order' , t => {
83
83
t . plan ( 2 )
84
84
const fastify = Fastify ( )
85
- fastify . register ( compressPlugin , { brotli } )
85
+ fastify . register ( compressPlugin , { brotli, global : false } )
86
86
87
87
fastify . get ( '/' , ( req , reply ) => {
88
88
reply . type ( 'text/plain' ) . compress ( createReadStream ( './package.json' ) )
@@ -105,7 +105,7 @@ test('should follow the encoding order', t => {
105
105
test ( 'Unsupported encoding' , t => {
106
106
t . plan ( 2 )
107
107
const fastify = Fastify ( )
108
- fastify . register ( compressPlugin )
108
+ fastify . register ( compressPlugin , { global : false } )
109
109
110
110
fastify . get ( '/' , ( req , reply ) => {
111
111
reply . type ( 'text/plain' ) . compress ( createReadStream ( './package.json' ) )
@@ -131,7 +131,7 @@ test('Unsupported encoding', t => {
131
131
test ( 'Missing header' , t => {
132
132
t . plan ( 2 )
133
133
const fastify = Fastify ( )
134
- fastify . register ( compressPlugin )
134
+ fastify . register ( compressPlugin , { global : false } )
135
135
136
136
fastify . get ( '/' , ( req , reply ) => {
137
137
reply . type ( 'text/plain' ) . compress ( createReadStream ( './package.json' ) )
@@ -154,7 +154,7 @@ test('Missing header', t => {
154
154
test ( 'Should close the stream' , t => {
155
155
t . plan ( 3 )
156
156
const fastify = Fastify ( )
157
- fastify . register ( compressPlugin )
157
+ fastify . register ( compressPlugin , { global : false } )
158
158
159
159
fastify . get ( '/' , ( req , reply ) => {
160
160
const stream = createReadStream ( './package.json' )
@@ -179,7 +179,7 @@ test('Should close the stream', t => {
179
179
test ( 'No compression header' , t => {
180
180
t . plan ( 2 )
181
181
const fastify = Fastify ( )
182
- fastify . register ( compressPlugin )
182
+ fastify . register ( compressPlugin , { global : false , threshold : 0 } )
183
183
184
184
fastify . get ( '/' , ( req , reply ) => {
185
185
reply . compress ( { hello : 'world' } )
@@ -201,7 +201,7 @@ test('No compression header', t => {
201
201
test ( 'Should compress json data (gzip)' , t => {
202
202
t . plan ( 1 )
203
203
const fastify = Fastify ( )
204
- fastify . register ( compressPlugin )
204
+ fastify . register ( compressPlugin , { global : false , threshold : 0 } )
205
205
const json = { hello : 'world' }
206
206
207
207
fastify . get ( '/' , ( req , reply ) => {
@@ -223,7 +223,7 @@ test('Should compress json data (gzip)', t => {
223
223
test ( 'Should compress json data (deflate)' , t => {
224
224
t . plan ( 1 )
225
225
const fastify = Fastify ( )
226
- fastify . register ( compressPlugin )
226
+ fastify . register ( compressPlugin , { global : false , threshold : 0 } )
227
227
const json = { hello : 'world' }
228
228
229
229
fastify . get ( '/' , ( req , reply ) => {
@@ -245,7 +245,7 @@ test('Should compress json data (deflate)', t => {
245
245
test ( 'Should compress json data (brotli)' , t => {
246
246
t . plan ( 1 )
247
247
const fastify = Fastify ( )
248
- fastify . register ( compressPlugin , { brotli } )
248
+ fastify . register ( compressPlugin , { global : false , brotli, threshold : 0 } )
249
249
const json = { hello : 'world' }
250
250
251
251
fastify . get ( '/' , ( req , reply ) => {
@@ -267,7 +267,7 @@ test('Should compress json data (brotli)', t => {
267
267
test ( 'Should compress string data (gzip)' , t => {
268
268
t . plan ( 1 )
269
269
const fastify = Fastify ( )
270
- fastify . register ( compressPlugin )
270
+ fastify . register ( compressPlugin , { global : false , threshold : 0 } )
271
271
272
272
fastify . get ( '/' , ( req , reply ) => {
273
273
reply . type ( 'text/plain' ) . compress ( 'hello' )
@@ -288,7 +288,7 @@ test('Should compress string data (gzip)', t => {
288
288
test ( 'Should compress string data (deflate)' , t => {
289
289
t . plan ( 1 )
290
290
const fastify = Fastify ( )
291
- fastify . register ( compressPlugin )
291
+ fastify . register ( compressPlugin , { global : false , threshold : 0 } )
292
292
293
293
fastify . get ( '/' , ( req , reply ) => {
294
294
reply . type ( 'text/plain' ) . compress ( 'hello' )
@@ -309,7 +309,7 @@ test('Should compress string data (deflate)', t => {
309
309
test ( 'Should compress string data (brotli)' , t => {
310
310
t . plan ( 1 )
311
311
const fastify = Fastify ( )
312
- fastify . register ( compressPlugin , { brotli } )
312
+ fastify . register ( compressPlugin , { brotli, threshold : 0 } )
313
313
314
314
fastify . get ( '/' , ( req , reply ) => {
315
315
reply . type ( 'text/plain' ) . compress ( 'hello' )
@@ -330,7 +330,7 @@ test('Should compress string data (brotli)', t => {
330
330
test ( 'Missing payload' , t => {
331
331
t . plan ( 2 )
332
332
const fastify = Fastify ( )
333
- fastify . register ( compressPlugin )
333
+ fastify . register ( compressPlugin , { global : false } )
334
334
335
335
fastify . get ( '/' , ( req , reply ) => {
336
336
reply . compress ( )
@@ -353,7 +353,7 @@ test('Missing payload', t => {
353
353
test ( 'Should compress json data (gzip) - global' , t => {
354
354
t . plan ( 1 )
355
355
const fastify = Fastify ( )
356
- fastify . register ( compressPlugin , { global : true } )
356
+ fastify . register ( compressPlugin , { threshold : 0 } )
357
357
const json = { hello : 'world' }
358
358
359
359
fastify . get ( '/' , ( req , reply ) => {
@@ -375,7 +375,7 @@ test('Should compress json data (gzip) - global', t => {
375
375
test ( 'Should compress json data (deflate) - global' , t => {
376
376
t . plan ( 1 )
377
377
const fastify = Fastify ( )
378
- fastify . register ( compressPlugin , { global : true } )
378
+ fastify . register ( compressPlugin , { threshold : 0 } )
379
379
const json = { hello : 'world' }
380
380
381
381
fastify . get ( '/' , ( req , reply ) => {
@@ -397,7 +397,7 @@ test('Should compress json data (deflate) - global', t => {
397
397
test ( 'Should compress json data (brotli) - global' , t => {
398
398
t . plan ( 1 )
399
399
const fastify = Fastify ( )
400
- fastify . register ( compressPlugin , { global : true , brotli } )
400
+ fastify . register ( compressPlugin , { brotli , threshold : 0 } )
401
401
const json = { hello : 'world' }
402
402
403
403
fastify . get ( '/' , ( req , reply ) => {
@@ -415,3 +415,47 @@ test('Should compress json data (brotli) - global', t => {
415
415
t . strictEqual ( payload . toString ( 'utf-8' ) , JSON . stringify ( json ) )
416
416
} )
417
417
} )
418
+
419
+ test ( 'identity header (compress)' , t => {
420
+ t . plan ( 2 )
421
+ const fastify = Fastify ( )
422
+ fastify . register ( compressPlugin , { global : false , threshold : 0 } )
423
+
424
+ fastify . get ( '/' , ( req , reply ) => {
425
+ reply . compress ( { hello : 'world' } )
426
+ } )
427
+
428
+ fastify . inject ( {
429
+ url : '/' ,
430
+ method : 'GET' ,
431
+ headers : {
432
+ 'accept-encoding' : 'identity'
433
+ }
434
+ } , res => {
435
+ const payload = JSON . parse ( res . payload )
436
+ t . notOk ( res . headers [ 'content-encoding' ] )
437
+ t . deepEqual ( { hello : 'world' } , payload )
438
+ } )
439
+ } )
440
+
441
+ test ( 'identity header (hook)' , t => {
442
+ t . plan ( 2 )
443
+ const fastify = Fastify ( )
444
+ fastify . register ( compressPlugin , { threshold : 0 } )
445
+
446
+ fastify . get ( '/' , ( req , reply ) => {
447
+ reply . send ( { hello : 'world' } )
448
+ } )
449
+
450
+ fastify . inject ( {
451
+ url : '/' ,
452
+ method : 'GET' ,
453
+ headers : {
454
+ 'accept-encoding' : 'identity'
455
+ }
456
+ } , res => {
457
+ const payload = JSON . parse ( res . payload )
458
+ t . notOk ( res . headers [ 'content-encoding' ] )
459
+ t . deepEqual ( { hello : 'world' } , payload )
460
+ } )
461
+ } )
0 commit comments