Skip to content
Myr

Revert "remove old OPTIONS default response"

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

This reverts commit 2bba69f6333eddaa140346ef3ee3226c5efb5195.

authored by TJ Holowaychuk · committed by TJ Holowaychuk · parent 8fe1e2a · Browse files · 2 files+75 added−0 removed
This commit

State

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

Diff stats

2 files+75 added−0 removed

  • tests:+37 added−0 removed
  • other:+38 added−0 removed

2 files+75 added−0 removed

modified:lib/router/index.js+38 added
101 unmodified lines
102103 // match route104 req.route = route = self.matchRequest(req, i);105106 // implied OPTIONS107 if (!route && 'OPTIONS' == req.method) return self._options(req, res);108109 // no route110 if (!route) return next(err);111 debug('matched %s %s', route.method, route.path);112
60 unmodified lines
173 })(0);174};175176/**177 * Respond to __OPTIONS__ method.178 *179 * @param {IncomingMessage} req180 * @param {ServerResponse} res181 * @api private182 */183184Router.prototype._options = function(req, res){185 var path = parse(req).pathname186 , body = this._optionsFor(path).join(',');187 res.set('Allow', body).send(body);188};189190/**191 * Return an array of HTTP verbs or "options" for `path`.192 *193 * @param {String} path194 * @return {Array}195 * @api private196 */197198Router.prototype._optionsFor = function(path){199 var self = this;200 return methods.filter(function(method){201 var routes = self.map[method];202 if (!routes || 'options' == method) return;203 for (var i = 0, len = routes.length; i < len; ++i) {204 if (routes[i].match(path)) return true;205 }206 }).map(function(method){207 return method.toUpperCase();208 });209};210211/**212 * Attempt to match a route for `req`213 * with optional starting index of `i`214 * defaulting to 0.215 *
96 unmodified lines
added:test/app.options.js+37 added