http: always parse json for compatability. fixes #146.
This commit is contained in:
parent
96d093fb64
commit
49bb9ed0fa
@ -154,6 +154,7 @@ HTTPBase.prototype.handleRequest = co(function* handleRequest(req, res) {
|
|||||||
|
|
||||||
HTTPBase.prototype.parseBody = co(function* parseBody(req) {
|
HTTPBase.prototype.parseBody = co(function* parseBody(req) {
|
||||||
var body = Object.create(null);
|
var body = Object.create(null);
|
||||||
|
var type = req.contentType;
|
||||||
var data;
|
var data;
|
||||||
|
|
||||||
if (req.method === 'GET')
|
if (req.method === 'GET')
|
||||||
@ -164,7 +165,10 @@ HTTPBase.prototype.parseBody = co(function* parseBody(req) {
|
|||||||
if (!data)
|
if (!data)
|
||||||
return body;
|
return body;
|
||||||
|
|
||||||
switch (req.contentType) {
|
if (this.options.contentType)
|
||||||
|
type = this.options.contentType;
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
case 'json':
|
case 'json':
|
||||||
body = JSON.parse(data);
|
body = JSON.parse(data);
|
||||||
break;
|
break;
|
||||||
@ -507,6 +511,8 @@ function HTTPBaseOptions(options) {
|
|||||||
this.keyLimit = 100;
|
this.keyLimit = 100;
|
||||||
this.bodyLimit = 20 << 20;
|
this.bodyLimit = 20 << 20;
|
||||||
|
|
||||||
|
this.contentType = null;
|
||||||
|
|
||||||
if (options)
|
if (options)
|
||||||
this.fromOptions(options);
|
this.fromOptions(options);
|
||||||
}
|
}
|
||||||
@ -569,6 +575,11 @@ HTTPBaseOptions.prototype.fromOptions = function fromOptions(options) {
|
|||||||
this.ssl = options.ssl;
|
this.ssl = options.ssl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.contentType != null) {
|
||||||
|
assert(typeof options.contentType === 'string');
|
||||||
|
this.contentType = options.contentType;
|
||||||
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1734,6 +1734,7 @@ function HTTPOptions(options) {
|
|||||||
this.key = null;
|
this.key = null;
|
||||||
this.cert = null;
|
this.cert = null;
|
||||||
this.ca = null;
|
this.ca = null;
|
||||||
|
this.contentType = 'json';
|
||||||
|
|
||||||
this.fromOptions(options);
|
this.fromOptions(options);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user