Skip to content
Myr

Change the approach to be truth based

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Now just enforces that a plugin returns true, if it doesn't return true then we assume the plugin is taking care of making sure that the plugin chain continues. A sensible enhancement to this might be to improve the request.trigger function to timeout after a fixed period, log a warning, then carry on as normal ?? I'm not too sure of what 'Hooks.js' does so I may haveconfigured that incorrectly, just FYI

authored by ciaranj · committed by ciaranj · parent 27ff134 · Browse files · 10 files+32 added−29 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

10 files+32 added−29 removed

  • other:+32 added−29 removed

10 files+32 added−29 removed

modified:lib/express/plugins/body-decoder.js+2 added-3 removed
modified:lib/express/plugins/common-logger.js+5 added-3 removed
modified:lib/express/plugins/content-length.js+2 added-2 removed
modified:lib/express/plugins/cookie.js+4 added-4 removed
89 unmodified lines
90 /**91 * Parse request cookie data.92 */93 94 request: function(event, callback) {94 request: function(event) {95 event.request.response.cookies = []96 event.request.cookies = event.request.headers.cookie97 ? exports.parseCookie(event.request.headers.cookie)98 : {}99 callback()99 return true;100 },101 102 /**103 * Set the Set-Cookie header when response cookies are available.104 */105 106 response: function(event, callback) {106 response: function(event) {107 if (event.response.cookies.length)108 event.request.header('set-cookie', event.response.cookies.join(', '))109 callback();109 return true;110 }111 }112})
modified:lib/express/plugins/method-override.js+2 added-3 removed
modified:lib/express/plugins/profiler.js+4 added-4 removed
modified:lib/express/plugins/redirect.js+2 added-2 removed
47 unmodified lines
48 * Assign home to 'home', 'basepath' or '/'.49 * Assign back to 'referrer' or 'referer' headers.50 */51 52 request: function(event, callback) {52 request: function(event) {53 event.request.home = set('home') || set('basepath') || '/'54 event.request.back = event.request.header('referrer') || event.request.header('referer')55 callback();55 return true;56 }57 }58})
modified:lib/express/plugins/session.js+4 added-4 removed
183 unmodified lines
184 /**185 * Create session id when not found; delegate to store.186 */187 188 request: function(event, callback) {188 request: function(event) {189 var sid190 if (!(sid = event.request.cookie('sid')))191 event.request.cookie('sid', sid = utils.uid(), set('session cookie'))192 event.request.session = exports.Session.store.fetch(sid)193 event.request.session.touch()194 callback();194 return true;195 },196 197 /**198 * Delegate to store, allowing it to save sessions changes.199 */200 201 response: function(event, callback) {201 response: function(event) {202 exports.Session.store.commit(event.request.session)203 callback()203 return true;204 }205 }206})
modified:lib/express/plugin.js+2 added-3 removed
54 unmodified lines
55 56 trigger: function(event, callback) {57 if ('on' in this)58 if (event.name in this.on)59 this.on[event.name].call(this, event, callback)60 else callback()61 else callback()59 return this.on[event.name].call(this, event, callback)60 return true;61 }62})
modified:lib/express/request.js+5 added-1 removed
227 unmodified lines
228 //TODO: we'd want to use the nice collection stuff that was here instead of this crappy approach...229 var pluginsExecuted= 0,230 plugin= undefined,231 totalPlugins= this.plugins.length,232 pluginResult, 233 self= this;234 var callNextPlugin= function(error) {235 if( error || pluginsExecuted >= totalPlugins ) callback(error); // All the plugins have called back or there was an error ..236 else {237 try{238 plugin= self.plugins.at(pluginsExecuted++);238 if( plugin && plugin.trigger ) plugin.trigger(new Event(name, data), callNextPlugin)239 if( plugin && plugin.trigger ) {240 pluginResult= plugin.trigger(new Event(name, data), callNextPlugin);241 if(pluginResult) callNextPlugin() // If the plugin returned true then it handled the event inline, otherwise we assume it is going to call the callback itself.242 }243 else callNextPlugin();244 } catch(e) {245 callNextPlugin(e);246 }
48 unmodified lines