On MDN Fetch
Theres this example:
const myInit = {
method: 'GET',
headers: {
'Accept': 'image/jpeg'
},
mode: 'cors',
cache: 'default'
};
let myRequest = new Request('flowers.jpg', myInit);
You can see the headers object is just a normal object literal, but when I try, this code does not add the custom header:
const PWA_FETCH_BYPASS = "X-PWA-Fetch-Bypass"
let init = {
headers: {
PWA_FETCH_BYPASS: 'true'
},
}
let response = await fetch(url, init)
But this code does add the custom header:
const PWA_FETCH_BYPASS = "X-PWA-Fetch-Bypass"
let myHeaders = new Headers();
myHeaders.append(PWA_FETCH_BYPASS, 'true')
const init = {
headers: myHeaders
}
let response = await fetch(url, init)
Why does object literal version not add the custom header?