Code working in Chrome with native fetch, but not Safari with the polyfill.
See original GitHub issueI have the following code:
fetch('//api.mysite/url', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
}
});
My Access-Control-Request-Headers
contains content-type
(note case), which works using native fetch in Chrome, but fails in Safari using this polyfill:
Failed to load resource: Request header field Content-Type is not allowed by Access-Control-Allow-Headers.
Initially I thought it was something to do with case, but lowercasing Content-Type
didn’t seem to fix it.
Per RFC 7230, headers should be case insensitive anyway: "Each header field consists of a case-insensitive field name followed by a colon (“😊, optional leading whitespace, the field value, and optional trailing whitespace.”
Any ideas what could be causing this? If it’s a bug, happy to contribute a fix.
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (1 by maintainers)
Top Results From Across the Web
Safari not setting CORS cookies using JS Fetch API
The same code works correctly in FF and Chrome (I tested using both native and polyfill fetch ). The request is across domains;;...
Read more >Fetch API - MDN Web Docs
Fetch provides a generic definition of Request and Response objects (and other things involved with network requests).
Read more >What are Polyfills? - JavaScript in Plain English
To provide an example, let's say that fetch is not supported on all browsers, and we use it frequently in our application. /*...
Read more >Polyfill JavaScript Only When You Need To - CSS-Tricks
It is simply a way of triggering your own code when the polyfills have loaded, intended to allow the polyfill service to be...
Read more >Top 5: Best JavaScript Polyfills for the Fetch API
Chrome ; Firefox; Safari 6.1+; Internet Explorer 10+. On modern browsers such as Chrome, Firefox, Microsoft Edge, and Safari contain native ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
try:
I had an issue using the fetch API to get an image from an AWS S3 bucket. I was receiving a CORS issue on some of the images. Adding
fixed the issue.