function(raw, request, callback) { 
  var response = this;
  this._raw = raw;

  // The `._setHeaders` method is "private"; you can't otherwise set headers on
  // the response.
  this._setHeaders.call(this,raw.headers);
  
  // store any cookies
  if (request.cookieJar && this.getHeader('set-cookie')) {
    var cookieStrings = this.getHeader('set-cookie');
    var cookieObjs = []
      , cookie;

    for (var i = 0; i < cookieStrings.length; i++) {
      var cookieString = cookieStrings[i];
      if (!cookieString) {
        continue;
      }

      if (!cookieString.match(/domain\=/i)) {
        cookieString += '; domain=' + request.host;
      }

      if (!cookieString.match(/path\=/i)) {
        cookieString += '; path=' + request.path;
      }

      try {
        cookie = new Cookie(cookieString);
        if (cookie) {
          cookieObjs.push(cookie);
        }
      } catch (e) {
        console.warn("Tried to set bad cookie: " + cookieString);
      }
    }

    request.cookieJar.setCookies(cookieObjs);
  }

  this.request = request;
  this.client = request.client;
  this.log = this.request.log;

  // Stream the response content entity and fire the callback when we're done.
  // Store the incoming data in a array of Buffers which we concatinate into one
  // buffer at the end.  We need to use buffers instead of strings here in order
  // to preserve binary data.
  var chunkBuffers = [];
  var dataLength = 0;
  raw.on("data", function(chunk) {
    chunkBuffers.push(chunk);
    dataLength += chunk.length;
  });
  raw.on("end", function() {
    var body;
    if (typeof Buffer === 'undefined') {
      // Just concatinate into a string
      body = chunkBuffers.join('');
    } else {
      // Initialize new buffer and add the chunks one-at-a-time.
      body = new Buffer(dataLength);
      for (var i = 0, pos = 0; i < chunkBuffers.length; i++) {
        chunkBuffers[i].copy(body, pos);
        pos += chunkBuffers[i].length;
      }
    }

    var setBodyAndFinish = function (body) {
      response._body = new Content({ 
        body: body,
        type: response.getHeader("Content-Type")
      });
      callback(response);
    }

    if (zlib && response.getHeader("Content-Encoding") === 'gzip'){
      zlib.gunzip(body, function (err, gunzippedBody) {
        if (Iconv && response.request.encoding){
          body = Iconv.fromEncoding(gunzippedBody,response.request.encoding);
        } else {
          body = gunzippedBody.toString();
        }
        setBodyAndFinish(body);
      })
    }
    else{
       if (response.request.encoding){
            body = Iconv.fromEncoding(body,response.request.encoding);
        }        
      setBodyAndFinish(body);
    }
  });
}
function(raw, request, callback) { 
  var response = this;
  this._raw = raw;

  // The `._setHeaders` method is "private"; you can't otherwise set headers on
  // the response.
  this._setHeaders.call(this,raw.headers);
  
  // store any cookies
  if (request.cookieJar && this.getHeader('set-cookie')) {
    var cookieStrings = this.getHeader('set-cookie');
    var cookieObjs = []
      , cookie;

    for (var i = 0; i < cookieStrings.length; i++) {
      var cookieString = cookieStrings[i];
      if (!cookieString) {
        continue;
      }

      if (!cookieString.match(/domain\=/i)) {
        cookieString += '; domain=' + request.host;
      }

      if (!cookieString.match(/path\=/i)) {
        cookieString += '; path=' + request.path;
      }

      try {
        cookie = new Cookie(cookieString);
        if (cookie) {
          cookieObjs.push(cookie);
        }
      } catch (e) {
        console.warn("Tried to set bad cookie: " + cookieString);
      }
    }

    request.cookieJar.setCookies(cookieObjs);
  }

  this.request = request;
  this.client = request.client;
  this.log = this.request.log;

  // Stream the response content entity and fire the callback when we're done.
  // Store the incoming data in a array of Buffers which we concatinate into one
  // buffer at the end.  We need to use buffers instead of strings here in order
  // to preserve binary data.
  var chunkBuffers = [];
  var dataLength = 0;
  raw.on("data", function(chunk) {
    chunkBuffers.push(chunk);
    dataLength += chunk.length;
  });
  raw.on("end", function() {
    var body;
    if (typeof Buffer === 'undefined') {
      // Just concatinate into a string
      body = chunkBuffers.join('');
    } else {
      // Initialize new buffer and add the chunks one-at-a-time.
      body = new Buffer(dataLength);
      for (var i = 0, pos = 0; i < chunkBuffers.length; i++) {
        chunkBuffers[i].copy(body, pos);
        pos += chunkBuffers[i].length;
      }
    }

    var setBodyAndFinish = function (body) {
      response._body = new Content({ 
        body: body,
        type: response.getHeader("Content-Type")
      });
      callback(response);
    }

    if (zlib && response.getHeader("Content-Encoding") === 'gzip'){
      zlib.gunzip(body, function (err, gunzippedBody) {
        if (Iconv && response.request.encoding){
          body = Iconv.fromEncoding(gunzippedBody,response.request.encoding);
        } else {
          body = gunzippedBody.toString();
        }
        setBodyAndFinish(body);
      })
    }
    else{
       if (response.request.encoding){
            body = Iconv.fromEncoding(body,response.request.encoding);
        }        
      setBodyAndFinish(body);
    }
  });
}
function ( raw , request , callback ) { var response = this ; this . _raw = raw ; // The `._setHeaders` method is "private"; you can't otherwise set headers on // the response. this . _setHeaders . call ( this , raw . headers ) ; // store any cookies if ( request . cookieJar && this . getHeader ( 'set-cookie' ) ) { var cookieStrings = this . getHeader ( 'set-cookie' ) ; var cookieObjs = [ ] , cookie ; for ( var i = 0 ; i < cookieStrings . length ; i ++ ) { var cookieString = cookieStrings [ i ] ; if ( ! cookieString ) { continue ; } if ( ! cookieString . match ( / domain\= / i ) ) { cookieString += '; domain=' + request . host ; } if ( ! cookieString . match ( / path\= / i ) ) { cookieString += '; path=' + request . path ; } try { cookie = new Cookie ( cookieString ) ; if ( cookie ) { cookieObjs . push ( cookie ) ; } } catch ( e ) { console . warn ( "Tried to set bad cookie: " + cookieString ) ; } } request . cookieJar . setCookies ( cookieObjs ) ; } this . request = request ; this . client = request . client ; this . log = this . request . log ; // Stream the response content entity and fire the callback when we're done. // Store the incoming data in a array of Buffers which we concatinate into one // buffer at the end.  We need to use buffers instead of strings here in order // to preserve binary data. var chunkBuffers = [ ] ; var dataLength = 0 ; raw . on ( "data" , function ( chunk ) { chunkBuffers . push ( chunk ) ; dataLength += chunk . length ; } ) ; raw . on ( "end" , function ( ) { var body ; if ( typeof Buffer === 'undefined' ) { // Just concatinate into a string body = chunkBuffers . join ( '' ) ; } else { // Initialize new buffer and add the chunks one-at-a-time. body = new Buffer ( dataLength ) ; for ( var i = 0 , pos = 0 ; i < chunkBuffers . length ; i ++ ) { chunkBuffers [ i ] . copy ( body , pos ) ; pos += chunkBuffers [ i ] . length ; } } var setBodyAndFinish = function ( body ) { response . _body = new Content ( { body : body , type : response . getHeader ( "Content-Type" ) } ) ; callback ( response ) ; } if ( zlib && response . getHeader ( "Content-Encoding" ) === 'gzip' ) { zlib . gunzip ( body , function ( err , gunzippedBody ) { if ( Iconv && response . request . encoding ) { body = Iconv . fromEncoding ( gunzippedBody , response . request . encoding ) ; } else { body = gunzippedBody . toString ( ) ; } setBodyAndFinish ( body ) ; } ) } else { if ( response . request . encoding ) { body = Iconv . fromEncoding ( body , response . request . encoding ) ; } setBodyAndFinish ( body ) ; } } ) ; }
Construct a `Response` object. You should never have to do this directly. The `Request` object handles this, getting the raw response object and passing it in here, along with the request. The callback allows us to stream the response and then use the callback to let the request know when it's ready.
Construct a Response object . You should never have to do this directly . The Request object handles this getting the raw response object and passing it in here along with the request . The callback allows us to stream the response and then use the callback to let the request know when it s ready .