misc fixes.

This commit is contained in:
Christopher Jeffrey 2016-02-22 23:31:05 -08:00
parent 1ced7af7b4
commit 5923726e78
2 changed files with 33 additions and 28 deletions

View File

@ -256,34 +256,35 @@ HTTPServer.prototype._initRouter = function _initRouter() {
return done(new Error('No routes found.'));
(function next() {
var route, path, callback, compiled, matched;
if (i === routes.length)
return done(new Error('Route not found.'));
route = routes[i++];
path = route.path;
callback = route.callback;
if (!route.regex) {
compiled = compilePath(path);
route.regex = compiled.regex;
route.map = compiled.map;
}
matched = route.regex.exec(req.pathname);
if (!matched)
return next();
req.params = {};
matched.slice(1).forEach(function(item, i) {
if (route.map[i])
req.params[route.map[i]] = item;
req.params[i] = item;
});
// Avoid stack overflows
utils.nextTick(function() {
var route, path, callback, compiled, matched;
if (i === routes.length)
return done(new Error('Route not found.'));
route = routes[i++];
path = route.path;
callback = route.callback;
if (!route.regex) {
compiled = compilePath(path);
route.regex = compiled.regex;
route.map = compiled.map;
}
matched = route.regex.exec(req.pathname);
if (!matched)
return next();
req.params = {};
matched.slice(1).forEach(function(item, i) {
if (route.map[i])
req.params[route.map[i]] = item;
req.params[i] = item;
});
try {
callback(req, res, next, _send);
} catch (e) {

View File

@ -1421,7 +1421,11 @@ utils.ccmp = function(a, b) {
var res = 0;
var i;
assert(a.length === b.length);
assert(Buffer.isBuffer(a));
assert(Buffer.isBuffer(b));
if (a.length !== b.length)
return false;
for (i = 0; i < a.length; i++)
res |= a[i] ^ b[i];