Skip to content
Myr

Fixed `req.is()` with charsets

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 014fb46 · Browse files · 1 file+8 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

1 file+8 added−6 removed

  • other:+8 added−6 removed

1 file+8 added−6 removed

modified:lib/request.js+8 added-6 removed
307 unmodified lines
308309req.is = function(type){310 var fn = this.app.is(type);311 if (fn) return fn(this);312 var contentType = this.headers['content-type'];313 if (!contentType) return false;312 var ct = this.headers['content-type'];313 if (!ct) return false;314 ct = ct.split(';')[0];315 if (!~type.indexOf('/')) type = mime.lookup(type);316 if (~type.indexOf('*')) {317 type = type.split('/');317 contentType = contentType.split('/');318 if ('*' == type[0] && type[1] == contentType[1]) return true;319 if ('*' == type[1] && type[0] == contentType[0]) return true;318 ct = ct.split('/');319 if ('*' == type[0] && type[1] == ct[1]) return true;320 if ('*' == type[1] && type[0] == ct[0]) return true;321 return false;322 }321 return !! ~contentType.indexOf(type);323 return !! ~ct.indexOf(type);324};325326/**327 * Short-hand for `req.connection.encrypted`.
56 unmodified lines