From 763be9f1200110540777c351bf30b48c83d34e4c Mon Sep 17 00:00:00 2001
From: Volker Schukai <volker.schukai@schukai.com>
Date: Tue, 21 Jan 2025 01:05:17 +0100
Subject: [PATCH] fix: check header by rest api

---
 source/data/datasource/server/restapi.mjs | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/source/data/datasource/server/restapi.mjs b/source/data/datasource/server/restapi.mjs
index 0a341bf2a..e42bc5263 100644
--- a/source/data/datasource/server/restapi.mjs
+++ b/source/data/datasource/server/restapi.mjs
@@ -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;
-- 
GitLab