parse req.type by media-typer
This commit is contained in:
parent
690604b6d2
commit
5b18f8bab0
3 changed files with 4 additions and 4 deletions
|
@ -7,6 +7,7 @@ var qs = require('querystring');
|
||||||
var typeis = require('type-is');
|
var typeis = require('type-is');
|
||||||
var fresh = require('fresh');
|
var fresh = require('fresh');
|
||||||
var url = require('url');
|
var url = require('url');
|
||||||
|
var typer = require('media-typer');
|
||||||
var stringify = url.format;
|
var stringify = url.format;
|
||||||
var parse = url.parse;
|
var parse = url.parse;
|
||||||
|
|
||||||
|
@ -272,12 +273,10 @@ module.exports = {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
get charset() {
|
get charset() {
|
||||||
// TODO: lame, we could have a generic param parsing lib
|
|
||||||
var type = this.get('Content-Type');
|
var type = this.get('Content-Type');
|
||||||
if (!type) return;
|
if (!type) return;
|
||||||
|
|
||||||
var m = type.match(/charset *= *(\S+)/);
|
return typer.parse(type).parameters.charset;
|
||||||
if (m) return m[1];
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
"accepts": "~1.0.0",
|
"accepts": "~1.0.0",
|
||||||
"type-is": "~1.3.1",
|
"type-is": "~1.3.1",
|
||||||
"mime-types": "~1.0.0",
|
"mime-types": "~1.0.0",
|
||||||
|
"media-typer": "~0.2.0",
|
||||||
"finished": "~1.2.0",
|
"finished": "~1.2.0",
|
||||||
"co": "~3.0.2",
|
"co": "~3.0.2",
|
||||||
"debug": "*",
|
"debug": "*",
|
||||||
|
|
|
@ -25,4 +25,4 @@ describe('req.charset', function(){
|
||||||
req.charset.should.equal('utf-8');
|
req.charset.should.equal('utf-8');
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue