Reading response headers with Fetch API

后端 未结 6 1598
Happy的楠姐
Happy的楠姐 2020-11-28 06:42

I\'m in a Google Chrome extension with permissions for \"*://*/*\" and I\'m trying to make the switch from XMLHttpRequest to the Fetch API.

The extensio

6条回答
  •  一生所求
    2020-11-28 07:01

    There is a restriction to access response headers when you are using Fetch API over CORS. Due to this restriction, you can access only following standard headers:

    • Cache-Control
    • Content-Language
    • Content-Type
    • Expires
    • Last-Modified
    • Pragma

    When you are writing code for Google Chrome extension, you are using CORS, hence you can't access all headers. If you control the server, you can return custom information in the response body instead of headers

    More info on this restriction - https://developers.google.com/web/updates/2015/03/introduction-to-fetch#response_types

提交回复
热议问题