Merge pull request #312 from dead-horse/typer

parse req.type by media-typer
This commit is contained in:
Jonathan Ong 2014-07-09 19:51:16 -07:00
commit 1b806a1d39
3 changed files with 4 additions and 4 deletions

View file

@ -7,6 +7,7 @@ var qs = require('querystring');
var typeis = require('type-is');
var fresh = require('fresh');
var url = require('url');
var typer = require('media-typer');
var stringify = url.format;
var parse = url.parse;
@ -272,12 +273,10 @@ module.exports = {
*/
get charset() {
// TODO: lame, we could have a generic param parsing lib
var type = this.get('Content-Type');
if (!type) return;
var m = type.match(/charset *= *(\S+)/);
if (m) return m[1];
return typer.parse(type).parameters.charset;
},
/**

View file

@ -26,6 +26,7 @@
"accepts": "~1.0.0",
"type-is": "~1.3.1",
"mime-types": "~1.0.0",
"media-typer": "~0.2.0",
"finished": "~1.2.0",
"co": "~3.0.2",
"debug": "*",

View file

@ -25,4 +25,4 @@ describe('req.charset', function(){
req.charset.should.equal('utf-8');
})
})
})
})