Skip to content
Myr

Fix routing regression when altering req.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 b4b2efe · Browse files · 3 files+40 added−6 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+40 added−6 removed

  • tests:+31 added−1 removed
  • other:+9 added−5 removed

3 files+40 added−6 removed

modified:lib/router/index.js+4 added-5 removed
113 unmodified lines
114 var self = this;115116 debug('dispatching %s %s', req.method, req.url);117118 var method = req.method.toLowerCase();119118 var search = 1 + req.url.indexOf('?');119 var pathlength = search ? search - 1 : req.url.length;120 var fqdn = 1 + req.url.substr(0, pathlength).indexOf('://');121 var protohost = fqdn ? req.url.substr(0, req.url.indexOf('/', 2 + fqdn)) : '';
17 unmodified lines
139 // setup next layer140 req.next = next;141142 // for options requests, respond with a default if nothing else responds145 if (method === 'options') {143 if (req.method === 'OPTIONS') {144 done = wrap(done, function(old, err) {145 if (err || options.length === 0) return old(err);146147 var body = options.join(',');
40 unmodified lines
188 if (err) {189 return next(err);190 }191192 var method = req.method;193 var has_method = route._handles_method(method);194195 // build up automatic options response197 if (!has_method && method === 'options') {196 if (!has_method && method === 'OPTIONS') {197 options.push.apply(options, route._options());198 }199200 // don't even bother202 if (!has_method && method !== 'head') {201 if (!has_method && method !== 'HEAD') {202 return next();203 }204205 // we can now dispatch to the route
313 unmodified lines
modified:test/app.router.js+31 added-1 removed
12var after = require('after');3var express = require('../')4 , request = require('supertest')5 , assert = require('assert')6 , methods = require('methods');
25 unmodified lines
32 .expect('x-user-id', '1')33 .expect(200, '1', done);34 })3535 describe('methods supported', function(){36 describe('methods', function(){37 methods.concat('del').forEach(function(method){38 if (method === 'connect') return;3940 it('should include ' + method.toUpperCase(), function(done){
17 unmodified lines
58 var app = express();59 app[method].bind(app, '/', 3).should.throw(/Number/);60 })61 });6263 it('should re-route when method is altered', function (done) {64 var app = express();65 var cb = after(3, done);6667 app.use(function (req, res, next) {68 if (req.method !== 'POST') return next();69 req.method = 'DELETE';70 res.setHeader('X-Method-Altered', '1');71 next();72 });7374 app.delete('/', function (req, res) {75 res.end('deleted everything');76 });7778 request(app)79 .get('/')80 .expect(404, 'Cannot GET /\n', cb);8182 request(app)83 .delete('/')84 .expect(200, 'deleted everything', cb);8586 request(app)87 .post('/')88 .expect('X-Method-Altered', '1')89 .expect(200, 'deleted everything', cb);90 });91 })9293 describe('decode querystring', function(){94 it('should decode correct params', function(done){
726 unmodified lines
modified:History.md+5 added
1unreleased2==========34 * fix routing regression when altering `req.method`564.5.0 / 2014-07-047==================89 * add deprecation message to non-plural `req.accepts*`
1738 unmodified lines