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.3.1 to 0.4.0

27

index.js

@@ -13,3 +13,12 @@ 'use strict';

const supportedEncodings = ['gzip', 'deflate'];
const compressionStreams = {
gzip: zlib.createGzip,
deflate: zlib.createDeflate
}
if (opts.brotli) {
compressionStreams.br = opts.brotli;
supportedEncodings.push('br');
}
fastify.addHook('onSend', compression)

@@ -23,15 +32,10 @@

let payloadStream;
let _payload = payload;
if (!reply.res.getHeader('Content-Type') || reply.res.getHeader('Content-Type') === 'application/json') {
reply.res.setHeader('Content-Type', 'application/json');
_payload = reply.serialize(payload);
}
if (Buffer.byteLength(_payload) < threshold) {
if (Buffer.byteLength(payload) < threshold) {
done();
return;
}
payloadStream = stringToStream(_payload);
payloadStream = stringToStream(payload);
setVaryHeader(reply);
reply.header('Content-Encoding', method);
const compressionStream = method === 'gzip' ? zlib.createGzip() : zlib.createDeflate();
const compressionStream = compressionStreams[method]();

@@ -76,2 +80,7 @@ pump(payloadStream, compressionStream, onEnd.bind(request))

exports = module.exports = fastifyPlugin(compressionPlugin, '>=0.35.0');
const metadata = {
fastify: '>=0.43.0',
name: 'fastify-compression'
}
exports = module.exports = fastifyPlugin(compressionPlugin, metadata);
{
"name": "fastify-compression",
"version": "0.3.1",
"version": "0.4.0",
"description": "A compression plugin for fastify",

@@ -24,4 +24,4 @@ "main": "index.js",

"encoding-negotiator": "^1.0.2",
"fastify-plugin": "^0.1.1",
"pump": "^2.0.0",
"fastify-plugin": "^0.2.1",
"pump": "^3.0.0",
"string-to-stream": "^1.1.0"

@@ -38,3 +38,3 @@ },

"eslint": "^4.10.0",
"fastify": "^0.35.0",
"fastify": "^0.43.0",
"request": "^2.83.0",

@@ -41,0 +41,0 @@ "tap": "^11.0.0"

@@ -16,3 +16,4 @@ 'use strict';

const options = {}
fastify.register(fastifyCompression, options, (err) => {
fastify.register(fastifyCompression, options);
fastify.ready((err) => {
t.error(err);

@@ -140,3 +141,3 @@ });

t.strictEqual(response.headers['content-encoding'], 'gzip');
t.strictEqual(zlib.gunzipSync(body).toString('utf-8'), '"something larger than threshold"');
t.strictEqual(zlib.gunzipSync(body).toString('utf-8'), 'something larger than threshold');
})

@@ -173,3 +174,3 @@ });

t.strictEqual(response.headers['content-encoding'], 'gzip');
t.strictEqual(zlib.gunzipSync(body).toString('utf-8'), '"something larger than threshold"');
t.strictEqual(zlib.gunzipSync(body).toString('utf-8'), 'something larger than threshold');
})

@@ -268,3 +269,3 @@ });

t.notOk(response.headers['content-length']);
t.strictEqual(zlib.gunzipSync(body).toString('utf-8'), '"something larger than threshold"');
t.strictEqual(zlib.gunzipSync(body).toString('utf-8'), 'something larger than threshold');
})

@@ -271,0 +272,0 @@ });

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