http: always parse json for compatability. fixes #146.

This commit is contained in:
Christopher Jeffrey 2017-02-28 05:26:48 -08:00
parent 96d093fb64
commit 49bb9ed0fa
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 13 additions and 1 deletions

View File

@ -154,6 +154,7 @@ HTTPBase.prototype.handleRequest = co(function* handleRequest(req, res) {
HTTPBase.prototype.parseBody = co(function* parseBody(req) {
var body = Object.create(null);
var type = req.contentType;
var data;
if (req.method === 'GET')
@ -164,7 +165,10 @@ HTTPBase.prototype.parseBody = co(function* parseBody(req) {
if (!data)
return body;
switch (req.contentType) {
if (this.options.contentType)
type = this.options.contentType;
switch (type) {
case 'json':
body = JSON.parse(data);
break;
@ -507,6 +511,8 @@ function HTTPBaseOptions(options) {
this.keyLimit = 100;
this.bodyLimit = 20 << 20;
this.contentType = null;
if (options)
this.fromOptions(options);
}
@ -569,6 +575,11 @@ HTTPBaseOptions.prototype.fromOptions = function fromOptions(options) {
this.ssl = options.ssl;
}
if (options.contentType != null) {
assert(typeof options.contentType === 'string');
this.contentType = options.contentType;
}
return this;
};

View File

@ -1734,6 +1734,7 @@ function HTTPOptions(options) {
this.key = null;
this.cert = null;
this.ca = null;
this.contentType = 'json';
this.fromOptions(options);
}