Fake PATCH/PUT/DELETE requests

closes #502
This commit is contained in:
Toby Zerner 2015-10-14 12:46:59 +10:30
parent 77807c4bb8
commit 2b19cf39e1

View File

@ -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.