fastify-compression
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -33,4 +33,5 @@ 'use strict'; | ||
const compressionStream = method === 'gzip' ? zlib.createGzip() : zlib.createDeflate(); | ||
done(null, pump(payloadStream, compressionStream, onEnd.bind(request))); | ||
pump(payloadStream, compressionStream, onEnd.bind(request)) | ||
done(null, compressionStream); | ||
return; | ||
@@ -54,3 +55,3 @@ } | ||
return 'deflate'; | ||
} else if (encoding === 'gzip') { | ||
} else if (encoding === 'gzip' || encoding === '*') { | ||
return 'gzip'; | ||
@@ -57,0 +58,0 @@ } |
{ | ||
"name": "fastify-compression", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "A compression plugin for fastify", | ||
@@ -24,3 +24,3 @@ "main": "index.js", | ||
"fastify-plugin": "^0.1.1", | ||
"pump": "^1.0.3", | ||
"pump": "^2.0.0", | ||
"string-to-stream": "^1.1.0" | ||
@@ -39,4 +39,4 @@ }, | ||
"request": "^2.83.0", | ||
"tap": "^10.7.2" | ||
"tap": "^11.0.0" | ||
} | ||
} |
@@ -22,3 +22,3 @@ # fastify-compression | ||
### compression(fastify, options, next) | ||
Compresses the payload with `gzip` or `deflate` if the payload length is above the threshold and a `Accept-Encoding` header is send with the request. | ||
Compresses the payload with `gzip` or `deflate` if the payload length is above the threshold and a `Accept-Encoding` header is send with the request. In case of an asterisk `*` in the `Accept-Encoding` header `gzip` will be chosen. | ||
### options | ||
@@ -25,0 +25,0 @@ #### threshold (optional) |
@@ -144,2 +144,34 @@ 'use strict'; | ||
test('support * accept-encoding', t => { | ||
t.plan(6); | ||
const fastify = Fastify(); | ||
const options = { | ||
threshold: 8 | ||
} | ||
fastify.register(fastifyCompression, options); | ||
fastify.get('/', (request, reply) => { | ||
reply.send("something larger than threshold"); | ||
}) | ||
fastify.listen(0, err => { | ||
fastify.server.unref(); | ||
t.error(err); | ||
request({ | ||
method: 'GET', | ||
uri: 'http://localhost:' + fastify.server.address().port, | ||
headers: { | ||
'accept-encoding': '*' | ||
}, | ||
encoding: null | ||
}, (err, response, body) => { | ||
t.error(err); | ||
t.notOk(response.headers['content-length']); | ||
t.strictEqual(response.statusCode, 200); | ||
t.strictEqual(response.headers['content-encoding'], 'gzip'); | ||
t.strictEqual(zlib.gunzipSync(body).toString('utf-8'), '"something larger than threshold"'); | ||
}) | ||
}); | ||
}); | ||
test('should compress if larger than threshold', t => { | ||
@@ -146,0 +178,0 @@ t.plan(6); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19184
472
+ Addedpump@2.0.1(transitive)
- Removedpump@1.0.3(transitive)
Updatedpump@^2.0.0