Support X-HTTP-Method-Override for old clients

This commit is contained in:
Aurélien Georget 2016-02-01 14:22:29 +01:00
parent 06549e6bb7
commit 348428132c

View File

@ -16,13 +16,24 @@ const utils = require('../utils/utils');
module.exports = {
default: {},
/**
* Parse request
*/
parse: function * (ctx) {
// Assign used method
this.default.method = ctx.method.toUpperCase();
// Detect X-HTTP-Method-Override for some clients
// which don't support PATCH method
if (ctx.header.hasOwnProperty('x-http-method-override') && ctx.header['x-http-method-override'] === 'PATCH') {
this.default.method = 'POST';
}
// HTTP methods allowed
switch (ctx.method.toUpperCase()) {
switch (this.default.method) {
case 'GET':
// Nothing to do
break;
@ -75,14 +86,14 @@ module.exports = {
message: 'Missing `data` member'
}
};
} else if (!utils.isRessourceObject(body.data) && ctx.method !== 'POST') {
} else if (!utils.isRessourceObject(body.data) && this.default.method !== 'POST') {
throw {
status: 403,
body: {
message: 'Invalid ressource object'
}
};
} else if (!body.data.hasOwnProperty('type') && ctx.method === 'POST') {
} else if (!body.data.hasOwnProperty('type') && this.default.method === 'POST') {
throw {
status: 403,
body: {