Skip to content
Myr

Fix routing requests without method

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

authored by Douglas Christopher Wilson · committed by Douglas Christopher Wilson · parent 9bc1742 · Browse files · 3 files+35 added−2 removed
This commit

State

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

Diff stats

3 files+35 added−2 removed

  • tests:+27 added−0 removed
  • other:+8 added−2 removed

3 files+35 added−2 removed

modified:lib/router/route.js+7 added-2 removed
58 unmodified lines
59 if (this.methods._all) {60 return true;61 }6263 var name = method.toLowerCase();63 // normalize name64 var name = typeof method === 'string'65 ? method.toLowerCase()66 : method6768 if (name === 'head' && !this.methods['head']) {69 name = 'get';70 }
34 unmodified lines
105106 if (stack.length === 0) {107 return done();108 }109 var method = typeof req.method === 'string'110 ? req.method.toLowerCase()111 : req.method112107 var method = req.method.toLowerCase();113 if (method === 'head' && !this.methods['head']) {114 method = 'get';115 }116
114 unmodified lines
modified:test/Router.js+27 added
59 unmodified lines
6061 router.handle({ method: 'GET' }, {}, done)62 })6364 it('handle missing method', function (done) {65 var all = false66 var router = new Router()67 var route = router.route('/foo')68 var use = false6970 route.post(function (req, res, next) { next(new Error('should not run')) })71 route.all(function (req, res, next) {72 all = true73 next()74 })75 route.get(function (req, res, next) { next(new Error('should not run')) })7677 router.get('/foo', function (req, res, next) { next(new Error('should not run')) })78 router.use(function (req, res, next) {79 use = true80 next()81 })8283 router.handle({ url: '/foo' }, {}, function (err) {84 if (err) return done(err)85 assert.ok(all)86 assert.ok(use)87 done()88 })89 })9091 it('should not stack overflow with many registered routes', function(done){92 this.timeout(5000) // long-running test9394 var handler = function(req, res){ res.end(new Error('wrong handler')) };
546 unmodified lines
modified:History.md+1 added
1unreleased2==========34 * Fix routing requests without method5 * deps: body-parser@1.20.26 - Fix strict json error message on Node.js 19+7 - deps: content-type@~1.0.58 - deps: raw-body@2.5.2
3589 unmodified lines