1.0.2 • Published 9 years ago

compress-response v1.0.2

Weekly downloads
3
License
MIT
Repository
github
Last release
9 years ago

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' }