Skip to content

Instantly share code, notes, and snippets.

@RainerBlessing
Created September 2, 2012 19:51
Show Gist options
  • Save RainerBlessing/3603926 to your computer and use it in GitHub Desktop.
Save RainerBlessing/3603926 to your computer and use it in GitHub Desktop.
A stub for https.get (node.js).
var url = require('url');
var fs = require('fs');
var HTTPSStub = function(){
var handlers={};
var get = function(optionsget, callback){
var p = url.parse(optionsget.path,true);
console.log(p.pathname);
console.log(p.query);
var res = {
on: function(handler, callback){
handlers[handler] = callback;
}
};
fs.readFile('templates'+p.pathname, function (err, data) {
if (err) throw err;
handlers['data'](data);
});
callback(res);
return res;
};
this.get = get;
return this;
};
exports.get = function(optionsget, callback){
return new HTTPSStub().get(optionsget, callback);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment