From c7c2d9a7559d004dd17e78c6575098d5520f789e Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Wed, 14 Oct 2015 12:46:59 +1030 Subject: [PATCH] Fake PATCH/PUT/DELETE requests closes #502 --- js/lib/App.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/js/lib/App.js b/js/lib/App.js index 627c3c2ac..b6ddfb612 100644 --- a/js/lib/App.js +++ b/js/lib/App.js @@ -6,6 +6,7 @@ import Translator from 'flarum/Translator'; import extract from 'flarum/utils/extract'; import patchMithril from 'flarum/utils/patchMithril'; import RequestError from 'flarum/utils/RequestError'; +import { extend } from 'flarum/extend'; /** * The `App` class provides a container for an application, as well as various @@ -189,6 +190,15 @@ export default class App { options.config = options.config || this.session.authorize.bind(this.session); options.background = options.background || true; + // If the method is something like PATCH or DELETE, which not all servers + // support, then we'll send it as a POST request with a the intended method + // specified in the X-Fake-Http-Method header. + if (options.method !== 'GET' && options.method !== 'POST') { + const method = options.method; + extend(options, 'config', (result, xhr) => xhr.setRequestHeader('X-Fake-Http-Method', method)); + options.method = 'POST'; + } + // When we deserialize JSON data, if for some reason the server has provided // a dud response, we don't want the application to crash. We'll show an // error message to the user instead.