Removed `app.is()` support
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by TJ Holowaychuk · committed by TJ Holowaychuk · parent 26fb403 · Browse files · 3 files·+3 added−33 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+3 added−33 removed
- tests:+0 added−1 removed
- other:+3 added−32 removed
Provenance
- Commit
edfe50e- Tree
15a6123- Author
TJ Holowaychuk <tj@vision-media.ca>- Committer
TJ Holowaychuk <tj@vision-media.ca>- Parent
26fb403
3 files changed+3 added−33 removed
modified:lib/application.js-16 removed
41 unmodified lines42 var self = this;43 this.cache = {};44 this.settings = {};45 this.engines = {};46- this.isCallbacks = {};46 this.viewCallbacks = [];47 this.defaultConfiguration();48 49 // route reflection methods240 unmodified lines290 return this;291 };292 293 /**295- * Register the given callback `fn` for the given `type`.296- *297- * @param {String} type298- * @param {Function} fn299- * @return {app} for chaining300- * @api public301- */302-303-app.is = function(type, fn){304- if (!fn) return this.isCallbacks[type];305- this.isCallbacks[type] = fn;306- return this;307-};308-309-/**294 * Assign `setting` to `val`, or return `setting`'s value.295 * Mounted servers inherit their parent server's settings.296 *297 * @param {String} setting229 unmodified linesmodified:lib/request.js+3 added-16 removed
265 unmodified lines266 *267 * // With Content-Type: text/html; charset=utf-8268 * req.is('html');269 * req.is('text/html');270+ * req.is('text/*');271 * // => true272 * 273 * // When Content-Type is application/json274 * req.is('json');275 * req.is('application/json');276+ * req.is('application/*');277 * // => true278 * 279 * req.is('html');280 * // => false281 * 280- * Ad-hoc callbacks can also be registered with Express, to perform281- * assertions again the request, for example if we need an expressive282- * way to check if our incoming request is an image, we can register "an image"283- * callback:284- * 285- * app.is('an image', function(req){286- * return 0 == req.headers['content-type'].indexOf('image');287- * });288- *289- * app.is('an attachment', function(req){290- * return 0 == req.headers['content-disposition'].indexOf('attachment');291- * });292- *282 * Now within our route callbacks, we can use to to assert content types283 * such as "image/jpeg", "image/png", etc.284 * 285 * app.post('/image/upload', function(req, res, next){297- * if (req.is('an image')) {286+ * if (req.is('image/*')) {287 * // do something288 * } else {289 * next();290 * }4 unmodified lines295 * @api public296 */297 298 req.is = function(type){310- var fn = this.app.is(type);311- if (fn) return fn(this);299 var ct = this.headers['content-type'];300 if (!ct) return false;301 ct = ct.split(';')[0];302 if (!~type.indexOf('/')) type = mime.lookup(type);68 unmodified linesmodified:test/req.is.js-1 removed
3 unmodified lines4567889101189 unmodified lines3 unmodified lines
function req(ct) { var req = { headers: { 'content-type': ct } , app: express() , __proto__: express.request };
return req;89 unmodified lines