为什么在 fetch 的响应中不能找到所有 headers?

Why not all headers can be found in fetch's response?

我正在尝试从 fetch 的响应中拦截 Set-Cookie response header

fetch('https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png', {
 method: 'get'
}).then(function(response) {
    for (var pair of response.headers.entries()) {
        console.log(`${pair[0]}: ${pair[1]}`);
    }
});

但并不是所有的 header(在开发人员工具网络中可以看到)都可以在那里找到!这是为什么?有什么办法可以得到我正在寻找的 header 吗?

澄清一下,我不是在寻找 cookie,但我想知道 Set-Cookie header 何时发送。

您无法阅读 Set-Cookie header,因为它被声明为禁止阅读。 github 上的 fetch polyfill 提供了合理的解释:

Like with XMLHttpRequest, the Set-Cookie response header returned from the server is a forbidden header name and therefore can't be programatically read with response.headers.get(). Instead, it's the browser's responsibility to handle new cookies being set (if applicable to the current URL). Unless they are HTTP-only, new cookies will be available through document.cookie.

https://github.com/github/fetch#receiving-cookies