Skip to content

Commit da3a743

Browse files
committed
backported req.is() charset fix
1 parent 09c9537 commit da3a743

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

lib/request.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -292,16 +292,18 @@ req.flash = function(type, msg){
292292
req.is = function(type){
293293
var fn = this.app.is(type);
294294
if (fn) return fn(this);
295-
var contentType = this.headers['content-type'];
296-
if (!contentType) return;
295+
var ct = this.headers['content-type'];
296+
if (!ct) return false;
297+
ct = ct.split(';')[0];
297298
if (!~type.indexOf('/')) type = mime.lookup(type);
298299
if (~type.indexOf('*')) {
299-
type = type.split('/')
300-
contentType = contentType.split('/');
301-
if ('*' == type[0] && type[1] == contentType[1]) return true;
302-
if ('*' == type[1] && type[0] == contentType[0]) return true;
300+
type = type.split('/');
301+
ct = ct.split('/');
302+
if ('*' == type[0] && type[1] == ct[1]) return true;
303+
if ('*' == type[1] && type[0] == ct[0]) return true;
304+
return false;
303305
}
304-
return !! ~contentType.indexOf(type);
306+
return !! ~ct.indexOf(type);
305307
};
306308

307309
// Callback for isXMLHttpRequest / xhr

0 commit comments

Comments
 (0)