Skip to content

Commit

Permalink
Fixed req.is() with charsets
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Dec 30, 2011
1 parent 014fb46 commit 26fb403
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/request.js
Expand Up @@ -309,16 +309,18 @@ req.param = function(name, defaultValue){
req.is = function(type){
var fn = this.app.is(type);
if (fn) return fn(this);
var contentType = this.headers['content-type'];
if (!contentType) return false;
var ct = this.headers['content-type'];
if (!ct) return false;
ct = ct.split(';')[0];
if (!~type.indexOf('/')) type = mime.lookup(type);
if (~type.indexOf('*')) {
type = type.split('/');
contentType = contentType.split('/');
if ('*' == type[0] && type[1] == contentType[1]) return true;
if ('*' == type[1] && type[0] == contentType[0]) return true;
ct = ct.split('/');
if ('*' == type[0] && type[1] == ct[1]) return true;
if ('*' == type[1] && type[0] == ct[0]) return true;
return false;
}
return !! ~contentType.indexOf(type);
return !! ~ct.indexOf(type);
};

/**
Expand Down

0 comments on commit 26fb403

Please sign in to comment.