forked from mystiq/hydrogen-web
Headers is a DOM specific class, use Map instead in HomeServerApi
This commit is contained in:
parent
69a8786f8f
commit
277c8af628
2 changed files with 11 additions and 4 deletions
|
@ -55,13 +55,13 @@ export class HomeServerApi {
|
|||
.join("&");
|
||||
url = `${url}?${queryString}`;
|
||||
let bodyString;
|
||||
const headers = new Headers();
|
||||
const headers = new Map();
|
||||
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) {
|
||||
headers.append("Content-Type", "application/json");
|
||||
headers.set("Content-Type", "application/json");
|
||||
bodyString = JSON.stringify(body);
|
||||
}
|
||||
const requestResult = this._requestFn(url, {
|
||||
|
|
|
@ -44,6 +44,13 @@ export function fetchRequest(url, options) {
|
|||
referrer: "no-referrer",
|
||||
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 {status} = response;
|
||||
const body = await response.json();
|
||||
|
|
Loading…
Reference in a new issue