fastify-compress
Advanced tools
Comparing version 0.5.1 to 0.6.0
12
index.js
@@ -69,3 +69,6 @@ 'use strict' | ||
this.header('Content-Encoding', encoding) | ||
this | ||
.header('Content-Encoding', encoding) | ||
.removeHeader('content-length') | ||
var stream = compressStream[encoding]() | ||
@@ -111,3 +114,6 @@ pump(payload, stream, onEnd.bind(this)) | ||
reply.header('Content-Encoding', encoding) | ||
reply | ||
.header('Content-Encoding', encoding) | ||
.removeHeader('content-length') | ||
var stream = compressStream[encoding]() | ||
@@ -157,4 +163,4 @@ pump(payload, stream, onEnd.bind(reply)) | ||
module.exports = fp(compressPlugin, { | ||
fastify: '>=1.0.0', | ||
fastify: '>=1.3.0', | ||
name: 'fastify-compress' | ||
}) |
{ | ||
"name": "fastify-compress", | ||
"version": "0.5.1", | ||
"version": "0.6.0", | ||
"description": "Fastify compression utils", | ||
"main": "index.js", | ||
"dependencies": { | ||
"fastify-plugin": "^0.2.2", | ||
"fastify-plugin": "^1.0.0", | ||
"mime-db": "^1.33.0", | ||
@@ -13,7 +13,8 @@ "pump": "^3.0.0", | ||
"devDependencies": { | ||
"fastify": "^1.2.0", | ||
"fastify": "^1.3.0", | ||
"iltorb": "^2.3.0", | ||
"jsonstream": "^1.0.3", | ||
"iltorb": "^2.3.0", | ||
"pre-commit": "^1.2.2", | ||
"standard": "^11.0.1", | ||
"tap": "^11.1.3" | ||
"tap": "^11.1.4" | ||
}, | ||
@@ -20,0 +21,0 @@ "scripts": { |
# fastify-compress | ||
[![Greenkeeper badge](https://badges.greenkeeper.io/fastify/fastify-compress.svg)](https://greenkeeper.io/) | ||
[![Build Status](https://travis-ci.org/fastify/fastify-compress.svg?branch=master)](https://travis-ci.org/fastify/fastify-compress) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/) | ||
@@ -4,0 +6,0 @@ |
63
test.js
@@ -15,3 +15,3 @@ 'use strict' | ||
test('should send a deflated data', t => { | ||
t.plan(3) | ||
t.plan(4) | ||
const fastify = Fastify() | ||
@@ -33,2 +33,3 @@ fastify.register(compressPlugin, { global: false }) | ||
t.strictEqual(res.headers['content-encoding'], 'deflate') | ||
t.notOk(res.headers['content-length'], 'no content length') | ||
const file = readFileSync('./package.json', 'utf8') | ||
@@ -745,1 +746,61 @@ const payload = zlib.inflateSync(res.rawPayload) | ||
}) | ||
test('compress should remove content-length', t => { | ||
t.plan(4) | ||
const fastify = Fastify() | ||
fastify.register(compressPlugin, { global: false }) | ||
fastify.get('/', (req, reply) => { | ||
fs.readFile('./package.json', 'utf8', (err, data) => { | ||
if (err) { | ||
return reply.send(err) | ||
} | ||
reply.type('text/plain').header('content-length', '' + data.length).compress(data) | ||
}) | ||
}) | ||
fastify.inject({ | ||
url: '/', | ||
method: 'GET', | ||
headers: { | ||
'accept-encoding': 'deflate' | ||
} | ||
}, (err, res) => { | ||
t.error(err) | ||
t.strictEqual(res.headers['content-encoding'], 'deflate') | ||
t.notOk(res.headers['content-length'], 'no content length') | ||
const file = readFileSync('./package.json', 'utf8') | ||
const payload = zlib.inflateSync(res.rawPayload) | ||
t.strictEqual(payload.toString('utf-8'), file) | ||
}) | ||
}) | ||
test('onSend hook should remove content-length', t => { | ||
t.plan(4) | ||
const fastify = Fastify() | ||
fastify.register(compressPlugin, { global: true }) | ||
fastify.get('/', (req, reply) => { | ||
fs.readFile('./package.json', 'utf8', (err, data) => { | ||
if (err) { | ||
return reply.send(err) | ||
} | ||
reply.type('text/plain').header('content-length', '' + data.length).send(data) | ||
}) | ||
}) | ||
fastify.inject({ | ||
url: '/', | ||
method: 'GET', | ||
headers: { | ||
'accept-encoding': 'deflate' | ||
} | ||
}, (err, res) => { | ||
t.error(err) | ||
t.strictEqual(res.headers['content-encoding'], 'deflate') | ||
t.notOk(res.headers['content-length'], 'no content length') | ||
const file = readFileSync('./package.json', 'utf8') | ||
const payload = zlib.inflateSync(res.rawPayload) | ||
t.strictEqual(payload.toString('utf-8'), file) | ||
}) | ||
}) |
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
29010
837
91
6
+ Addedfastify-plugin@1.6.1(transitive)
+ Addedsemver@6.3.1(transitive)
- Removedfastify-plugin@0.2.2(transitive)
- Removedsemver@5.7.2(transitive)
Updatedfastify-plugin@^1.0.0