http-base: remove useless asserts and loops.
This commit is contained in:
parent
0b296a1a6f
commit
c28589d0e6
@ -287,12 +287,6 @@ HTTPBase.prototype.use = function use(path, callback, ctx) {
|
|||||||
path = null;
|
path = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Array.isArray(path)) {
|
|
||||||
for (i = 0; i < path.length; i++)
|
|
||||||
this.use(path[i], callback, ctx);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.stack.push(new Route(ctx, path, callback));
|
this.stack.push(new Route(ctx, path, callback));
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -303,17 +297,6 @@ HTTPBase.prototype.use = function use(path, callback, ctx) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
HTTPBase.prototype.get = function get(path, callback, ctx) {
|
HTTPBase.prototype.get = function get(path, callback, ctx) {
|
||||||
var i;
|
|
||||||
|
|
||||||
if (Array.isArray(path)) {
|
|
||||||
for (i = 0; i < path.length; i++)
|
|
||||||
this.get(path[i], callback, ctx);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(typeof path === 'string');
|
|
||||||
assert(path.length > 0);
|
|
||||||
|
|
||||||
this.routes.get.push(new Route(ctx, path, callback));
|
this.routes.get.push(new Route(ctx, path, callback));
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -324,17 +307,6 @@ HTTPBase.prototype.get = function get(path, callback, ctx) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
HTTPBase.prototype.post = function post(path, callback, ctx) {
|
HTTPBase.prototype.post = function post(path, callback, ctx) {
|
||||||
var i;
|
|
||||||
|
|
||||||
if (Array.isArray(path)) {
|
|
||||||
for (i = 0; i < path.length; i++)
|
|
||||||
this.post(path[i], callback, ctx);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(typeof path === 'string');
|
|
||||||
assert(path.length > 0);
|
|
||||||
|
|
||||||
this.routes.post.push(new Route(ctx, path, callback));
|
this.routes.post.push(new Route(ctx, path, callback));
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -345,17 +317,6 @@ HTTPBase.prototype.post = function post(path, callback, ctx) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
HTTPBase.prototype.put = function put(path, callback, ctx) {
|
HTTPBase.prototype.put = function put(path, callback, ctx) {
|
||||||
var i;
|
|
||||||
|
|
||||||
if (Array.isArray(path)) {
|
|
||||||
for (i = 0; i < path.length; i++)
|
|
||||||
this.put(path[i], callback, ctx);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(typeof path === 'string');
|
|
||||||
assert(path.length > 0);
|
|
||||||
|
|
||||||
this.routes.put.push(new Route(ctx, path, callback));
|
this.routes.put.push(new Route(ctx, path, callback));
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -366,17 +327,6 @@ HTTPBase.prototype.put = function put(path, callback, ctx) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
HTTPBase.prototype.del = function del(path, callback, ctx) {
|
HTTPBase.prototype.del = function del(path, callback, ctx) {
|
||||||
var i;
|
|
||||||
|
|
||||||
if (Array.isArray(path)) {
|
|
||||||
for (i = 0; i < path.length; i++)
|
|
||||||
this.del(path[i], callback, ctx);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(typeof path === 'string');
|
|
||||||
assert(path.length > 0);
|
|
||||||
|
|
||||||
this.routes.del.push(new Route(ctx, path, callback));
|
this.routes.del.push(new Route(ctx, path, callback));
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -441,6 +391,7 @@ function Route(ctx, path, callback) {
|
|||||||
this.regex = path;
|
this.regex = path;
|
||||||
} else {
|
} else {
|
||||||
assert(typeof path === 'string');
|
assert(typeof path === 'string');
|
||||||
|
assert(path.length > 0);
|
||||||
this.path = path;
|
this.path = path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -477,10 +428,10 @@ Route.prototype.compile = function compile() {
|
|||||||
Route.prototype.match = function match(pathname) {
|
Route.prototype.match = function match(pathname) {
|
||||||
var match;
|
var match;
|
||||||
|
|
||||||
assert(this.path);
|
|
||||||
|
|
||||||
this.compile();
|
this.compile();
|
||||||
|
|
||||||
|
assert(this.regex);
|
||||||
|
|
||||||
match = this.regex.exec(pathname);
|
match = this.regex.exec(pathname);
|
||||||
|
|
||||||
if (!match)
|
if (!match)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user