Headers is a DOM specific class, use Map instead in HomeServerApi

This commit is contained in:
Bruno Windels 2020-04-22 20:46:47 +02:00
parent 69a8786f8f
commit 277c8af628
2 changed files with 11 additions and 4 deletions

View file

@ -55,13 +55,13 @@ export class HomeServerApi {
.join("&"); .join("&");
url = `${url}?${queryString}`; url = `${url}?${queryString}`;
let bodyString; let bodyString;
const headers = new Headers(); const headers = new Map();
if (this._accessToken) { if (this._accessToken) {
headers.append("Authorization", `Bearer ${this._accessToken}`); headers.set("Authorization", `Bearer ${this._accessToken}`);
} }
headers.append("Accept", "application/json"); headers.set("Accept", "application/json");
if (body) { if (body) {
headers.append("Content-Type", "application/json"); headers.set("Content-Type", "application/json");
bodyString = JSON.stringify(body); bodyString = JSON.stringify(body);
} }
const requestResult = this._requestFn(url, { const requestResult = this._requestFn(url, {

View file

@ -44,6 +44,13 @@ export function fetchRequest(url, options) {
referrer: "no-referrer", referrer: "no-referrer",
cache: "no-cache", cache: "no-cache",
}); });
if (options.headers) {
const headers = new Headers();
for(const [name, value] of options.headers.entries()) {
headers.append(name, value);
}
options.headers = headers;
}
const promise = fetch(url, options).then(async response => { const promise = fetch(url, options).then(async response => {
const {status} = response; const {status} = response;
const body = await response.json(); const body = await response.json();