Permalink
Browse files

moving back to using 'request' after tempo optimization

  • Loading branch information...
1 parent c70ebda commit 6291185598c9c60da1a69fda4e33c3d22dcb9210 @jeffsu committed Sep 11, 2012
Showing with 10 additions and 23 deletions.
  1. +10 −23 lib/strategies/http.ms
@@ -1,30 +1,17 @@
-var http = require('http');
-var URL = require('url');
+var request = require('request');
+var URL = require('url');
module.exports = #(options) {
- var method = options.method || 'GET';
- var url = URL.parse(options.url);
-
- var reqOptions = {
- host: url.hostname,
- method: method,
- port: url.port,
- path: url.path
- };
+ var newOpts = {};
+ newOpts.__proto__ = options;
+ newOpts.url = URL.parse(options.url);
return #(cb) {
- var req = http.request(reqOptions);
-
- req.on('response', #(res) {
- var code = res.statusCode;
- var data = "";
-
- res.on('data', #(chunk) { data += chunk.toString(); });
- res.on('end', #{ cb(parseInt(code) >= 400, data) });
- res.on('close', #(err) { cb(err) });
+ var req = request(newOpts, #(e, r, body) {
+ if (e) return cb(e);
+ var code = r.statusCode;
+ if (parseInt(code) >= 400) return cb('error status code ' + code);
+ cb();
});
-
- req.on('error', #(err) { cb(err) });
- req.end();
};
};

0 comments on commit 6291185

Please sign in to comment.