Skip to content
Snippets Groups Projects
Verified Commit 7d0c6f61 authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

fix: set request header if not set

parent 4372d3c9
No related branches found
No related tags found
No related merge requests found
...@@ -66,7 +66,7 @@ class RestAPI extends Server { ...@@ -66,7 +66,7 @@ class RestAPI extends Server {
* @property {Object} write={} Options * @property {Object} write={} Options
* @property {Object} write.init={} An option object, containing any custom settings that you want to apply to the request. The parameters are identical to those of the {@link https://developer.mozilla.org/en-US/docs/Web/API/Request/Request|Request constructor} * @property {Object} write.init={} An option object, containing any custom settings that you want to apply to the request. The parameters are identical to those of the {@link https://developer.mozilla.org/en-US/docs/Web/API/Request/Request|Request constructor}
* @property {string} write.init.method=POST * @property {string} write.init.method=POST
* @property {Object} write.init.headers Object containing any custom headers that you want to apply to the request. * @property {Headers} write.init.headers Object containing any custom headers that you want to apply to the request.
* @property {string} write.responseCallback Callback function to be executed after the request has been completed. * @property {string} write.responseCallback Callback function to be executed after the request has been completed.
* @property {string} write.acceptedStatus=[200,201] * @property {string} write.acceptedStatus=[200,201]
* @property {string} write.url URL * @property {string} write.url URL
...@@ -141,13 +141,14 @@ class RestAPI extends Server { ...@@ -141,13 +141,14 @@ class RestAPI extends Server {
read() { read() {
let init = this.getOption("read.init"); let init = this.getOption("read.init");
if (!isObject(init)) init = {}; if (!isObject(init)) init = {};
if (!init["method"]) init["method"] = "GET"; if (!(init["headers"] instanceof Headers)) {
if (typeof init["headers"] !== "object") { init["headers"] = new Headers();
init["headers"] = { init["headers"].append("Accept", "application/json");
"Accept": "application/json", init["headers"].append("X-Requested-With", "XMLHttpRequest");
};
} }
if (!init["method"]) init["method"] = "GET";
let callback = this.getOption("read.responseCallback"); let callback = this.getOption("read.responseCallback");
if (!callback) { if (!callback) {
callback = (obj) => { callback = (obj) => {
...@@ -165,11 +166,10 @@ class RestAPI extends Server { ...@@ -165,11 +166,10 @@ class RestAPI extends Server {
write() { write() {
let init = this.getOption("write.init"); let init = this.getOption("write.init");
if (!isObject(init)) init = {}; if (!isObject(init)) init = {};
if (typeof init["headers"] !== "object") { if (!(init["headers"] instanceof Headers)) {
init["headers"] = { init["headers"] = new Headers();
"Content-Type": "application/json", init["headers"].append("Accept", "application/json");
"Accept": "application/json", init["headers"].append("Content-Type", "application/json");
};
} }
if (!init["method"]) init["method"] = "POST"; if (!init["method"]) init["method"] = "POST";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment