Closed gallak-openfin closed 1 year ago
Hello @gallak-openfin .
No sorry, I don't think there is a Response.headers on the Fetch specification, and this library tries to mimic it.
However, the example you gave would not show headers before they are sent, only after, as it is done after the await fetch
, no ? Or did I misunderstand something?
You may be able to use the Network tab of the dev tools while debugging the main process ( https://www.electronjs.org/docs/latest/tutorial/application-debugging#main-process ), but to be honest it's something I have never tried, and I have no idea if it would work.
I am closing this issue, but do not hesitate to still post a response here if you try it, whether it works or no.
(I meant "I don't think there is a Response.request.headers", sorry for the typo)
@arantes555 Heh sorry I wasn't clear, for my investigation I just need to print Request headers. But I just realized I can do it the same way for both electron-fetch and the native electron net module:
if (opts?.session) {
opts.session.webRequest.onBeforeSendHeaders((details, callback) => {
const reqHeaders = Object.entries(details.requestHeaders)
.map(([key, value]) => `${key}: ${value}`)
.join('; ');
console.log(`[fetch] Before send headers ${url}\nRequest Headers: ${reqHeaders}`);
callback({ requestHeaders: details.requestHeaders });
});
}
}
It does look like the request headers are identical, here is an example for a favicon fetch
electron-fetch
Request Headers: sec-ch-ua: "Not=A?Brand";v="99", "Chromium";v="118"; sec-ch-ua-mobile: ?0; User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.5993.0 OpenFin/35.118.78.29 Safari/537.36; sec-ch-ua-platform: "Windows"; Accept: image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8; Sec-Fetch-Site: same-origin; Sec-Fetch-Mode: no-cors; Sec-Fetch-Dest: image; Referer: http://localhost:3000/; Accept-Encoding: gzip, deflate, br, zstd; Accept-Language: en-US,en;q=0.9
net.request
Request Headers: sec-ch-ua: "Not=A?Brand";v="99", "Chromium";v="118"; sec-ch-ua-mobile: ?0; User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.5993.0 OpenFin/35.118.78.29 Safari/537.36; sec-ch-ua-platform: "Windows"; Accept: image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8; Sec-Fetch-Site: same-origin; Sec-Fetch-Mode: no-cors; Sec-Fetch-Dest: image; Referer: http://localhost:3000/; Accept-Encoding: gzip, deflate, br, zstd; Accept-Language: en-US,en;q=0.9
Hopefully this helps someone else.
Is there a way to get the default request headers that are set before it is sent?
My team is piloting switching to this library over electron net lib and I wanted to compare our request headers with this library's request headers. Thanks.