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

fix: check header by rest api

parent e440a937
No related branches found
No related tags found
No related merge requests found
......@@ -94,7 +94,10 @@ class RestAPI extends Server {
write: {
init: {
method: "POST",
headers: null,
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
},
responseCallback: null,
acceptedStatus: [200, 201],
......@@ -118,7 +121,9 @@ class RestAPI extends Server {
read: {
init: {
method: "GET",
headers: null,
headers: {
Accept: "application/json"
},
},
path: null,
responseCallback: null,
......@@ -141,10 +146,9 @@ class RestAPI extends Server {
read() {
let init = this.getOption("read.init");
if (!isObject(init)) init = {};
if (!(init["headers"] instanceof Headers)) {
if (!(init["headers"] instanceof Headers) && !isObject(init["headers"])) {
init["headers"] = new Headers();
init["headers"].append("Accept", "application/json");
init["headers"].append("X-Requested-With", "XMLHttpRequest");
}
if (!init["method"]) init["method"] = "GET";
......@@ -166,7 +170,7 @@ class RestAPI extends Server {
write() {
let init = this.getOption("write.init");
if (!isObject(init)) init = {};
if (!(init["headers"] instanceof Headers)) {
if (!(init["headers"] instanceof Headers) && !isObject(init["headers"])) {
init["headers"] = new Headers();
init["headers"].append("Accept", "application/json");
init["headers"].append("Content-Type", "application/json");
......@@ -206,6 +210,10 @@ class RestAPI extends Server {
function fetchData(init, key, callback) {
let response;
if (init?.headers === null) {
init.headers = new Headers();
}
return fetch(this.getOption(`${key}.url`), init)
.then((resp) => {
response = resp;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment