diff --git a/lib/routes/bins/create.js b/lib/routes/bins/create.js index 2cbd8081..01a75d8b 100644 --- a/lib/routes/bins/create.js +++ b/lib/routes/bins/create.js @@ -13,7 +13,8 @@ module.exports = function (req, res, next) { mock = req.jsonBody.response } - // overritten by application/x-www-form-urlencoded or multipart/form-data\ + // exception for the web Form + // TODO eliminate this and rely on req.simple.postData.text if (req.simple.postData.params && req.simple.postData.params.response) { try { mock = JSON.parse(req.simple.postData.params.response) @@ -22,10 +23,24 @@ module.exports = function (req, res, next) { } } + // overritten by application/x-www-form-urlencoded or multipart/form-data + if (req.simple.postData.text) { + try { + mock = JSON.parse(req.simple.postData.text) + } catch (e) { + debug(e) + } + } + // provide optional values before validation mock.redirectURL = '' mock.bodySize = 0 mock.headersSize = 0 + + if (!mock.content) { + mock.content = {} + } + mock.content.size = 0 validate.response(mock, function (err, valid) { diff --git a/package.json b/package.json index 4fddd333..d402fe06 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,4 @@ { - "version": "1.5.0", "name": "mockbin", "description": "Test, mock, and track HTTP requests & responses between libraries, sockets and APIs", "author": "Ahmad Nassri (https://www.mashape.com/)",