This repository has been archived by the owner on Mar 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
plugins: update & disable not implemented plugins
- Loading branch information
Showing
4 changed files
with
102 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
// | ||
// }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
// | ||
// }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
|
||
}; |