Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fastify-compression

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fastify-compression - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

7

index.js

@@ -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);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc