@fastify/compress 6.3.0 → 6.4.0
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 +1 -1
- package/package.json +2 -2
- package/test/global-compress.test.js +68 -0
package/index.js
CHANGED
|
@@ -107,7 +107,7 @@ function fastifyCompress (fastify, opts, next) {
|
|
|
107
107
|
next()
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
const defaultCompressibleTypes = /^text\/(?!event-stream)
|
|
110
|
+
const defaultCompressibleTypes = /^text\/(?!event-stream)|(\+|\/)json(;|$)|(\+|\/)text(;|$)|(\+|\/)xml(;|$)|octet-stream(;|$)/
|
|
111
111
|
|
|
112
112
|
function processCompressParams (opts) {
|
|
113
113
|
/* istanbul ignore next */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fastify/compress",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.4.0",
|
|
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": "^6.0.0",
|
|
13
13
|
"peek-stream": "^1.1.3",
|
|
14
14
|
"pump": "^3.0.0",
|
|
15
15
|
"pumpify": "^2.0.1"
|
|
@@ -3124,3 +3124,71 @@ test('It should return an error when using `reply.compress()` with a missing pay
|
|
|
3124
3124
|
statusCode: 500
|
|
3125
3125
|
}, payload)
|
|
3126
3126
|
})
|
|
3127
|
+
|
|
3128
|
+
const defaultSupportedContentTypes = [
|
|
3129
|
+
'application/json',
|
|
3130
|
+
'application/json; charset=utf-8',
|
|
3131
|
+
'application/graphql-response+json',
|
|
3132
|
+
'application/graphql-response+json; charset=utf-8',
|
|
3133
|
+
'application/xml',
|
|
3134
|
+
'application/xml; charset=utf-8',
|
|
3135
|
+
'octet-stream',
|
|
3136
|
+
'text/xml',
|
|
3137
|
+
'text/xml; charset=utf-8'
|
|
3138
|
+
]
|
|
3139
|
+
|
|
3140
|
+
for (const contentType of defaultSupportedContentTypes) {
|
|
3141
|
+
test(`It should compress data if content-type is supported by default, ${contentType}`, async (t) => {
|
|
3142
|
+
t.plan(2)
|
|
3143
|
+
const fastify = Fastify()
|
|
3144
|
+
await fastify.register(compressPlugin)
|
|
3145
|
+
|
|
3146
|
+
fastify.get('/', (request, reply) => {
|
|
3147
|
+
reply
|
|
3148
|
+
.type(contentType)
|
|
3149
|
+
.send(createReadStream('./package.json'))
|
|
3150
|
+
})
|
|
3151
|
+
|
|
3152
|
+
const response = await fastify.inject({
|
|
3153
|
+
url: '/',
|
|
3154
|
+
method: 'GET',
|
|
3155
|
+
headers: {
|
|
3156
|
+
'accept-encoding': 'gzip'
|
|
3157
|
+
}
|
|
3158
|
+
})
|
|
3159
|
+
const file = readFileSync('./package.json', 'utf8')
|
|
3160
|
+
const payload = zlib.gunzipSync(response.rawPayload)
|
|
3161
|
+
t.equal(response.headers['content-encoding'], 'gzip')
|
|
3162
|
+
t.equal(payload.toString('utf-8'), file)
|
|
3163
|
+
})
|
|
3164
|
+
}
|
|
3165
|
+
|
|
3166
|
+
const notByDefaultSupportedContentTypes = [
|
|
3167
|
+
'application/fastify',
|
|
3168
|
+
'text/event-stream'
|
|
3169
|
+
]
|
|
3170
|
+
|
|
3171
|
+
for (const contentType of notByDefaultSupportedContentTypes) {
|
|
3172
|
+
test(`It should not compress data if content-type is not supported by default, ${contentType}`, async (t) => {
|
|
3173
|
+
t.plan(2)
|
|
3174
|
+
const fastify = Fastify()
|
|
3175
|
+
await fastify.register(compressPlugin)
|
|
3176
|
+
|
|
3177
|
+
fastify.get('/', (request, reply) => {
|
|
3178
|
+
reply
|
|
3179
|
+
.type(contentType)
|
|
3180
|
+
.send(createReadStream('./package.json'))
|
|
3181
|
+
})
|
|
3182
|
+
|
|
3183
|
+
const response = await fastify.inject({
|
|
3184
|
+
url: '/',
|
|
3185
|
+
method: 'GET',
|
|
3186
|
+
headers: {
|
|
3187
|
+
'accept-encoding': 'gzip'
|
|
3188
|
+
}
|
|
3189
|
+
})
|
|
3190
|
+
const file = readFileSync('./package.json', 'utf8')
|
|
3191
|
+
t.notOk(response.headers['content-encoding'])
|
|
3192
|
+
t.equal(response.rawPayload.toString('utf-8'), file)
|
|
3193
|
+
})
|
|
3194
|
+
}
|