compress-response

1.0.2 • Public • Published

compress-responsebuild status

streaming http response compression thingy

NPM

NPM

Installation

npm install compress-response

Example

Input

var http = require('http')
 
  , compress = require('compress-response')
 
  , server = http.createServer(function (req, res) {
      res.setHeader('content-type', 'text/plan')
 
      var stream = compress(req, res)
      // @stream writes to res
      // if request had correct accept-encoding & type is compressible
      //  stream is a compressed stream to res
 
      stream.write('YEAH!')
      stream.end()
 
    })
 
require('servertest')(server, '/', { headers: { 'accept-encoding': 'gzip' } }, function (err, res) {
  console.log('body === "YEAH!"?')
  console.log(res.body.toString() === 'YEAH!')
  console.log('and these are the headers')
  console.log(res.headers)
})

Output

body === "YEAH!"?
false
and these are the headers
{ 'content-type': 'text/plan',
  'content-encoding': 'gzip',
  date: 'Sun, 16 Nov 2014 01:54:42 GMT',
  connection: 'close',
  'transfer-encoding': 'chunked' }

Readme

Keywords

none

Package Sidebar

Install

npm i compress-response

Weekly Downloads

1

Version

1.0.2

License

MIT

Last publish

Collaborators

  • kesla