Merge pull request #312 from dead-horse/typer
parse req.type by media-typer
This commit is contained in:
commit
1b806a1d39
3 changed files with 4 additions and 4 deletions
|
@ -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;
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -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": "*",
|
||||
|
|
|
@ -25,4 +25,4 @@ describe('req.charset', function(){
|
|||
req.charset.should.equal('utf-8');
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue