Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
plugins: update & disable not implemented plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
skenqbx committed Apr 23, 2015
1 parent 43df26f commit e49dd98
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 30 deletions.
25 changes: 18 additions & 7 deletions lib/plugins/auth.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
'use strict';


function authPlugin(rail, opt_options) {
opt_options = opt_options || {};

var pluginOptions = {
function AuthPlugin(rail, options) {
if (!(this instanceof AuthPlugin)) {
return new AuthPlugin(rail, options);
}
this._rail = rail;
this._intercept = null;

};

return pluginOptions;
this._setup();
}
module.exports = authPlugin;
module.exports = AuthPlugin;


AuthPlugin.prototype._setup = function() {
var self = this;
var rail = this._rail;

// rail.on('plugin-configure', function(call, options, request) {
//
// });
};
25 changes: 17 additions & 8 deletions lib/plugins/cache.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
'use strict';


function cachePlugin(rail, opt_options) {
opt_options = opt_options || {};

rail.use('buffer');
function CachePlugin(rail, options) {
if (!(this instanceof CachePlugin)) {
return new CachePlugin(rail, options);
}
this._rail = rail;
this._intercept = null;

var pluginOptions = {
this._setup();
}
module.exports = CachePlugin;

};

return pluginOptions;
}
module.exports = cachePlugin;
CachePlugin.prototype._setup = function() {
var self = this;
var rail = this._rail;

// rail.on('plugin-configure', function(call, options, request) {
//
// });
};
7 changes: 4 additions & 3 deletions lib/plugins/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
'use strict';

exports.auth = require('./auth');
// exports.auth = require('./auth');
exports.buffer = require('./buffer');
exports.cache = require('./cache');
// exports.cache = require('./cache');
exports.cookies = require('./cookies');
exports.json = require('./json');
exports.redirect = require('./redirect');
exports.retry = require('./retry');
// exports.retry = require('./retry');
exports.timeout = require('./timeout');
exports.validate = require('./validate');
75 changes: 63 additions & 12 deletions lib/plugins/retry.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,73 @@
'use strict';


function retryPlugin(rail, opt_options) {
opt_options = opt_options || {};

var pluginOptions = {
interval: opt_options.interval || 2000,
limit: opt_options.limit || 0
};
function RetryPlugin(rail, options) {
if (!(this instanceof RetryPlugin)) {
return new RetryPlugin(rail, options);
}
rail.use('timeout');

// TODO: on error: test different protocol
this._rail = rail;

this._intercepterror = null;
this._interceptrequest = null;

this.interval = options.interval || 2000;
this.limit = options.limit || 0;

this._setup();
}
module.exports = RetryPlugin;

rail.on('plugin-request', function(call, options, response) {
if (options.retry) {

RetryPlugin.prototype._setup = function() {
var self = this;
var rail = this._rail;

rail.on('plugin-configure', function(call, options) {
if (options.retry) {
if (!call.__buffer()) {
return call.emit('warn', 'retry', 'error', 'failed to enable send-buffer');
}
call.__intercept('error', self._intercepterror);
}
});

return pluginOptions;
}
module.exports = retryPlugin;
this._intercepterror = function(call, options, err) {
self._interceptError(call, options, err);
};

this._interceptrequest = function(call, options, request) {
self._interceptRequest(call, options, request);
};
};


RetryPlugin.prototype._interceptError = function(call, options, err) {
var config, req;
var syscall = err.syscall;

if (syscall === 'connect') {
config = call.__configure(options);

// TODO: try to auto-correct the config

call.__clear();
req = call.__request();

if (req && req !== true) {
call.__intercept('request', this._interceptrequest);
} else {
call.__emit('error', err);
}

} else {
call.__emit('error', err);
}
};


RetryPlugin.prototype._interceptRequest = function(call, options, request) {

};

0 comments on commit e49dd98

Please sign in to comment.