'use strict';
var agent = 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)';
var cheerio = require('cheerio');
var http = require('http');
var url = require('url');
var zlib = require('zlib');

/**
 * Requests or populate the resource from a HTTP resource.
 * @param {(string|!{address: string})} resource
 * @param {string} encoding
 * @param {function(Error, ?string)} done
 */
module.exports = function(resource, encoding, done) {
  if (typeof resource === 'string') return request(resource, encoding, done);
  populate(resource, encoding, done);
};

/**
 * Populates the resource from a HTTP resource.
 * @param {!{address: ?string}} resource
 * @param {string} encoding
 * @param {function(Error)} done
 */
function populate(resource, encoding, done) {
  if (!resource.address) return process.nextTick(done);
  request(resource.address, encoding, function(err, data) {
    if (err || !data) return done(err);
    var $ = cheerio.load(data);
    for (var key in resource) {
      if (typeof resource[key] === 'function') {
        resource[key] = resource[key]($);
      }
    }
    resource.address = undefined;
    done();
  });
}

/**
 * Requests a HTTP resource.
 * @param {string} path
 * @param {string} encoding
 * @param {function(Error, ?string)} done
 */
function request(path, encoding, done) {
  var options = url.parse(path);
  options.headers = {'User-Agent': agent};
  http.get(options, function(res) {
    var data = '';
    var resEncoding = res.headers['content-encoding'];
    res.setEncoding(encoding || 'utf8');
    if (resEncoding === 'gzip') {
      res.pipe(zlib.createGunzip());
    } else if (resEncoding === 'deflate') {
      res.pipe(zlib.createInflate());
    }
    res.on('data', function(chunk) {
      data += chunk;
    });
    res.on('end', function() {
      done(undefined, data || undefined);
    });
  }).on('error', done);
}

@@ -564,16 +564,267 @@
 e);%0A%7D;%0A%0A
+/**%0A * Retrieves the keys containing a function.%0A * @param %7B!Object%7D object%0A * @return %7B!Array.%3Cstring%3E%7D%0A */%0Afunction functions(object) %7B%0A  var map = %5B%5D;%0A  for (var key in object) if (typeof object%5Bkey%5D === 'function') map.push(key);%0A  return map;%0A%7D%0A%0A
 /**%0A * P
@@ -1216,79 +1216,43 @@
    f
-or (var key in resource) %7B%0A      if (typeof resource%5Bkey%5D === '
+unctions(resource).forEach(
 function
 ') %7B
@@ -1247,23 +1247,24 @@
 function
-'
+(key
 ) %7B%0A
-  
       re
@@ -1303,17 +1303,11 @@
     
-  %7D%0A    %7D
+%7D);
 %0A   

Optimize request for v8