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

fastify-compress

Package Overview
Dependencies
Maintainers
8
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fastify-compress - npm Package Compare versions

Comparing version 0.10.0 to 0.11.0

18

index.js

@@ -16,2 +16,3 @@ 'use strict'

const isDeflate = require('is-deflate')
const encodingNegotiator = require('encoding-negotiator')

@@ -37,3 +38,3 @@ function compressPlugin (fastify, opts, next) {

const supportedEncodings = ['deflate', 'gzip', 'identity']
const supportedEncodings = ['gzip', 'deflate', 'identity']
if (opts.brotli) {

@@ -167,15 +168,4 @@ compressStream.br = opts.brotli.compressStream

function getEncodingHeader (supportedEncodings, request) {
var header = request.headers['accept-encoding']
if (!header) return undefined
var acceptEncodings = header.split(',')
for (var i = 0; i < acceptEncodings.length; i++) {
var acceptEncoding = acceptEncodings[i].trim()
if (supportedEncodings.indexOf(acceptEncoding) > -1) {
return acceptEncoding
}
if (acceptEncoding.indexOf('*') > -1) {
return 'gzip'
}
}
return null
const header = request.headers['accept-encoding']
return encodingNegotiator.negotiate(header, supportedEncodings)
}

@@ -182,0 +172,0 @@

{
"name": "fastify-compress",
"version": "0.10.0",
"version": "0.11.0",
"description": "Fastify compression utils",
"main": "index.js",
"dependencies": {
"encoding-negotiator": "^2.0.0",
"fastify-plugin": "^1.0.0",

@@ -17,9 +18,9 @@ "into-stream": "4.0.0",

"pump": "^3.0.0",
"pumpify": "^1.3.3",
"string-to-stream": "^1.1.0",
"unzipper": "^0.9.11"
"pumpify": "^2.0.0",
"string-to-stream": "^2.0.0",
"unzipper": "^0.10.1"
},
"devDependencies": {
"@types/node": "^11.13.9",
"@typescript-eslint/parser": "^1.7.0",
"@types/node": "^12.0.8",
"@typescript-eslint/parser": "^2.0.0",
"eslint-plugin-typescript": "^0.14.0",

@@ -30,3 +31,3 @@ "fastify": "^2.0.0",

"pre-commit": "^1.2.2",
"standard": "^12.0.0",
"standard": "^14.0.2",
"typescript": "^3.4.5",

@@ -33,0 +34,0 @@ "tap": "^12.6.6"

@@ -45,3 +45,3 @@ # fastify-compress

const fs = require('fs')
const fastify = require('fastify')
const fastify = require('fastify')()

@@ -48,0 +48,0 @@ fastify.register(require('fastify-compress'), { global: false })

@@ -146,2 +146,29 @@ 'use strict'

test('should support quality syntax', t => {
t.plan(3)
const fastify = Fastify()
fastify.register(compressPlugin, { global: false })
fastify.get('/', (req, reply) => {
reply.type('text/plain').compress(
createReadStream('./package.json')
.pipe(zlib.createDeflate())
)
})
fastify.inject({
url: '/',
method: 'GET',
headers: {
'accept-encoding': 'gzip;q=0.5,deflate;q=0.6,identity;q=0.3'
}
}, (err, res) => {
t.error(err)
t.strictEqual(res.headers['content-encoding'], 'deflate')
const file = readFileSync('./package.json', 'utf8')
const payload = zlib.inflateSync(res.rawPayload)
t.strictEqual(payload.toString('utf-8'), file)
})
})
test('onSend hook should not double-compress Stream if already zipped', t => {

@@ -273,2 +300,29 @@ t.plan(3)

test('Unsupported encoding with quality value', t => {
t.plan(3)
const fastify = Fastify()
fastify.register(compressPlugin, { global: false })
fastify.get('/', (req, reply) => {
reply.type('text/plain').compress(createReadStream('./package.json'))
})
fastify.inject({
url: '/',
method: 'GET',
headers: {
'accept-encoding': 'lzma;q=1.0'
}
}, (err, res) => {
t.error(err)
const payload = JSON.parse(res.payload)
t.strictEqual(res.statusCode, 406)
t.deepEqual({
error: 'Not Acceptable',
message: 'Unsupported encoding',
statusCode: 406
}, payload)
})
})
test('should not compress on missing header', t => {

@@ -275,0 +329,0 @@ t.plan(3)

Sorry, the diff of this file is not supported yet

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