
var zlib = require('zlib')


function gzip (req, value) {
  req.on('response', function (res) {
    if (req._redirect) return
    var encoding = value || res.headers['content-encoding'] || 'identity'

    var decompress = null
    if (encoding.match(/\bdeflate\b/)) {
      decompress = zlib.createInflate()
    } else if (encoding.match(/\bgzip\b/)) {
      decompress = zlib.createGunzip()
    }

    req._res = (req._res || res).pipe(decompress)
  })
}

module.exports = gzip


var zlib = require('zlib')


function gzip (req, options) {
  options.headers['accept-encoding'] = 'gzip, deflate'

  req.on('response', function (res) {
    if (req._redirect) return

    var encoding = (/gzip|deflate/.test(options.gzip))
      ? options.gzip
      : (res.headers['content-encoding'] || 'identity')

    var decompress = null
    if (encoding.match(/\bdeflate\b/)) {
      decompress = zlib.createInflate()
    } else if (encoding.match(/\bgzip\b/)) {
      decompress = zlib.createGunzip()
    }

    req._res = (req._res || res).pipe(decompress)
  })
}

module.exports = gzip

Set accept-encoding header for gzip option
Set accept-encoding header for gzip option
