mirror of
https://github.com/zebrajr/express.git
synced 2025-12-06 00:19:48 +01:00
parent
efbc3f95ee
commit
269dc5323f
|
|
@ -11,6 +11,7 @@ unreleased
|
|||
* deprecate things with `depd` module
|
||||
* fix behavior when handling request without routes
|
||||
* fix handling when `route.all` is only route
|
||||
* invoke `router.param()` only when route matches
|
||||
* restore `req.params` after invoking router
|
||||
* use `finalhandler` for final response handling
|
||||
* use `media-typer` to alter content-type charset
|
||||
|
|
|
|||
|
|
@ -191,12 +191,20 @@ proto.handle = function(req, res, done) {
|
|||
return next(err);
|
||||
}
|
||||
|
||||
req.route = route;
|
||||
var has_method = route._handles_method(method);
|
||||
|
||||
// we can now dispatch to the route
|
||||
if (method === 'options' && !route.methods['options']) {
|
||||
// build up automatic options response
|
||||
if (!has_method && method === 'options') {
|
||||
options.push.apply(options, route._options());
|
||||
}
|
||||
|
||||
// don't even bother
|
||||
if (!has_method && method !== 'head') {
|
||||
return next();
|
||||
}
|
||||
|
||||
// we can now dispatch to the route
|
||||
req.route = route;
|
||||
}
|
||||
|
||||
// Capture one-time layer values
|
||||
|
|
|
|||
|
|
@ -28,6 +28,24 @@ function Route(path) {
|
|||
this.methods = {};
|
||||
}
|
||||
|
||||
/**
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Route.prototype._handles_method = function _handles_method(method) {
|
||||
if (this.methods._all) {
|
||||
return true;
|
||||
}
|
||||
|
||||
method = method.toLowerCase();
|
||||
|
||||
if (method === 'head' && !this.methods['head']) {
|
||||
method = 'get';
|
||||
}
|
||||
|
||||
return Boolean(this.methods[method]);
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {Array} supported HTTP methods
|
||||
* @api private
|
||||
|
|
@ -137,6 +155,7 @@ Route.prototype.all = function(){
|
|||
throw new Error(msg);
|
||||
}
|
||||
|
||||
self.methods._all = true;
|
||||
self.stack.push({ handle: fn });
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -177,6 +177,31 @@ describe('app', function(){
|
|||
.expect('loki', done);
|
||||
})
|
||||
|
||||
it('should not invoke without route handler', function(done) {
|
||||
var app = express();
|
||||
|
||||
app.param('thing', function(req, res, next, thing) {
|
||||
req.thing = thing;
|
||||
next();
|
||||
});
|
||||
|
||||
app.param('user', function(req, res, next, user) {
|
||||
next(new Error('invalid invokation'));
|
||||
});
|
||||
|
||||
app.post('/:user', function(req, res, next) {
|
||||
res.send(req.params.user);
|
||||
});
|
||||
|
||||
app.get('/:thing', function(req, res, next) {
|
||||
res.send(req.thing);
|
||||
});
|
||||
|
||||
request(app)
|
||||
.get('/bob')
|
||||
.expect(200, 'bob', done);
|
||||
})
|
||||
|
||||
it('should work with encoded values', function(done){
|
||||
var app = express();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user