Comparing version 1.1.5 to 1.2.0
@@ -29,3 +29,3 @@ | ||
exports.version = '1.1.5'; | ||
exports.version = '1.2.0'; | ||
@@ -32,0 +32,0 @@ /** |
@@ -19,3 +19,4 @@ | ||
* Enfore basic authentication by providing a `callback(user, pass)`, | ||
* which must return `true` in order to gain access. Populates | ||
* which must return `true` in order to gain access. Alternatively an async | ||
* method is provided as well, invoking `callback(user, pass, callback)`. Populates | ||
* `req.remoteUser`. | ||
@@ -25,3 +26,3 @@ * | ||
* | ||
* connect.createServer( | ||
* connect( | ||
* connect.basicAuth(function(user, pass){ | ||
@@ -32,2 +33,8 @@ * return 'tj' == user & 'wahoo' == pass; | ||
* | ||
* connect( | ||
* connect.basicAuth(function(user, pass, fn){ | ||
* User.authenticate({ user: user, pass: pass }, fn); | ||
* }) | ||
* ); | ||
* | ||
* @param {Function} callback | ||
@@ -53,7 +60,19 @@ * @param {String} realm | ||
if (callback(credentials[0], credentials[1])) { | ||
req.remoteUser = credentials[0]; | ||
next(); | ||
// async | ||
if (callback.length >= 3) { | ||
var pause = utils.pause(req); | ||
callback(credentials[0], credentials[1], function(err, user){ | ||
if (err || !user) return unauthorized(res, realm); | ||
req.remoteUser = user; | ||
next(); | ||
pause.resume(); | ||
}); | ||
// sync | ||
} else { | ||
unauthorized(res, realm); | ||
if (callback(credentials[0], credentials[1])) { | ||
req.remoteUser = credentials[0]; | ||
next(); | ||
} else { | ||
unauthorized(res, realm); | ||
} | ||
} | ||
@@ -60,0 +79,0 @@ } |
@@ -27,3 +27,2 @@ | ||
'get' | ||
, 'head' | ||
, 'post' | ||
@@ -104,3 +103,3 @@ , 'put' | ||
if (!fn) throw new Error(name + ' route ' + path + ' requires a callback'); | ||
path = path instanceof RegExp | ||
var regexp = path instanceof RegExp | ||
? path | ||
@@ -110,4 +109,6 @@ : normalizePath(path, keys); | ||
fn: fn | ||
, path: path | ||
, path: regexp | ||
, keys: keys | ||
, orig: path | ||
, method: name | ||
}); | ||
@@ -118,3 +119,3 @@ return self; | ||
return function router(req, res, next){ | ||
function router(req, res, next){ | ||
var route | ||
@@ -125,5 +126,5 @@ , self = this; | ||
var i = 0 | ||
, keys = route._keys; | ||
, keys = route.keys; | ||
req.params = route._params; | ||
req.params = route.params; | ||
@@ -176,2 +177,56 @@ // Param preconditions | ||
}; | ||
router.lookup = function(path, method, ret){ | ||
ret = ret || []; | ||
// method specific lookup | ||
if (method) { | ||
method = method.toUpperCase(); | ||
if (routes[method]) { | ||
routes[method].forEach(function(route){ | ||
if (path == route.orig) { | ||
var fn = route.fn; | ||
fn.regexp = route.path; | ||
fn.keys = route.keys; | ||
fn.path = route.orig; | ||
fn.method = route.method; | ||
ret.push(fn); | ||
} | ||
}); | ||
} | ||
// global lookup | ||
} else { | ||
_methods.forEach(function(method){ | ||
router.lookup(path, method, ret); | ||
}); | ||
} | ||
return ret; | ||
}; | ||
router.match = function(url, method, ret){ | ||
var ret = ret || [] | ||
, i = 0 | ||
, fn | ||
, req; | ||
// method specific matches | ||
if (method) { | ||
method = method.toUpperCase(); | ||
req = { url: url, method: method }; | ||
while (fn = match(req, routes, i)) { | ||
i = req._route_index + 1; | ||
ret.push(fn); | ||
} | ||
// global matches | ||
} else { | ||
_methods.forEach(function(method){ | ||
router.match(url, method, ret); | ||
}); | ||
} | ||
return ret; | ||
}; | ||
return router; | ||
} | ||
@@ -275,5 +330,6 @@ | ||
, path = route.path | ||
, keys = fn._keys = route.keys; | ||
, keys = fn.keys = route.keys; | ||
if (captures = path.exec(pathname)) { | ||
fn._params = []; | ||
fn.method = method; | ||
fn.params = []; | ||
for (var j = 1, len = captures.length; j < len; ++j) { | ||
@@ -285,5 +341,5 @@ var key = keys[j-1], | ||
if (key) { | ||
fn._params[key] = val; | ||
fn.params[key] = val; | ||
} else { | ||
fn._params.push(val); | ||
fn.params.push(val); | ||
} | ||
@@ -290,0 +346,0 @@ } |
{ | ||
"name": "connect", | ||
"version": "1.1.5", | ||
"version": "1.2.0", | ||
"description": "High performance middleware framework", | ||
@@ -8,2 +8,3 @@ "keywords": ["framework", "web", "middleware", "connect", "rack"], | ||
"author": "TJ Holowaychuk <tj@vision-media.ca> (http://tjholowaychuk.com)", | ||
"repository": "git://github.com/senchalabs/connect", | ||
"dependencies": { | ||
@@ -10,0 +11,0 @@ "qs": ">= 0.0.6", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
78494
2862