Skip to content

Instantly share code, notes, and snippets.

@Fauntleroy
Last active December 21, 2015 09:19
Show Gist options
  • Save Fauntleroy/6284162 to your computer and use it in GitHub Desktop.
Save Fauntleroy/6284162 to your computer and use it in GitHub Desktop.
var fetchResource = function( resource_url, callback ){
var parsed_url = url.parse( resource_url );
var response = '';
var req = http.request({
host: parsed_url.host,
hostname: parsed_url.hostname,
port: 80,
path: parsed_url.path,
method: 'GET',
rejectUnauthorized: false
}, function( res ){
res.on( 'error', callback );
res.on( 'data', function( chunk ){
response += chunk;
});
res.on( 'end', function(){
callback( null, response.toString( 'UTF8' ) );
req.end();
});
});
req.on( 'error', callback );
req.end();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment