I am trying to get the headers of the request and from our app i am sending authorization and geopoints but when i am logging the headers it gives an array of objects where 16 objects are there i am using this to log the headers
let requestHeaders = JSON.stringify([…request.headers])
console.log(new Map(request.headers))
and here is the code which i have tried
const html = `
Document
header is empty
`;
const html1 = `
Document
header is not empty
`;
addEventListener("fetch", (event) => {
return event.respondWith(handleRequest(event.request));
});
async function handleRequest(request) {
let requestHeaders = JSON.stringify([...request.headers]);
console.log(new Map(request.headers));
console.log(requestHeaders);
if (Object.keys(request.headers).length === 0) {
console.log("no header");
return new Response(html, {
headers: {
"content-type": "text/html;charset=UTF-8",
},
});
}
// else{
return new Response(html1, {
headers: {
"content-type": "text/html;charset=UTF-8",
},
});
}