mirror of
https://github.com/strapi/strapi.git
synced 2025-11-02 02:44:55 +00:00
Support X-HTTP-Method-Override for old clients
This commit is contained in:
parent
06549e6bb7
commit
348428132c
@ -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: {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user