
var bl = require('bl')
var utils = require('../lib/utils')


function callback (req, options) {
  var buffer = bl()
    , encoding = options.encoding
    , callback = options.callback

  req.on('data', function (chunk) {
    buffer.append(chunk)
  })

  req.on('end', function () {
    var body
    if (encoding === 'binary') {
      // binary
      body = buffer.slice()
    }
    else {
      // string
      body = buffer.toString()
      // json
      if (options.json && utils.isJSON(req._res, body)) {
        try {
          body = JSON.parse(body)
        }
        catch (err) {}
      }
    }
    callback(null, req._res, body)
  })
}

module.exports = callback

@@ -179,16 +179,86 @@
 llback%0A%0A
+  var _res%0A  req.on('response', function (res) %7B%0A    _res = res%0A  %7D)%0A%0A
   req.on
@@ -528,24 +528,8 @@
 if (
-options.json && 
 util
@@ -537,20 +537,16 @@
 .isJSON(
-req.
 _res, bo
@@ -666,20 +666,16 @@
 k(null, 
-req.
 _res, bo

Fix - return the original response object in callback