Bug 170985 - Failed to fetch with undefined headers
Summary: Failed to fetch with undefined headers
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: Safari 10
Hardware: Mac OS X 10.11
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-04-19 02:38 PDT by Cheng You Bai (:cybai)
Modified: 2017-04-20 20:47 PDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Cheng You Bai (:cybai) 2017-04-19 02:38:28 PDT
When I tried to use `fetch` with `undefined` headers, the promise will be rejected with `TypeError: undefined is not an object`.

Ex. `fetch('/my-awesome-api', { headers: undefined })`

```
TypeError: undefined is not an object
anonymous
fillFetchHeaders
initializeFetchRequest
[native code]
fetch
tryCatch
invoke
step
(anonymous function)
run
(anonymous function)
flush
```

I'm using OSX 10.11 El Capitan and on Safari 10.1 (11603.1.30.0.34).

I know there's another [bugzilla issue](https://bugs.webkit.org/show_bug.cgi?id=168043) about this issue.
However, I still face this issue.

If the fix is released yet, please kindly help me to close this issue.

Thanks.
Comment 1 youenn fablet 2017-04-20 08:19:13 PDT
The next Safari release will probably include it.
In the meantime, could you use a workaround like not setting the "headers" key when its value would be undefined?
Comment 2 Cheng You Bai (:cybai) 2017-04-20 18:51:38 PDT
Hi youenn fablet,

Yes, I've tried to use empty object to handle this issue and it works fine.

Ex.
``` 
fetch('/my-awesome-api', { headers: headers || {} });
```

Hope it will be released soon, thanks!
Comment 3 youenn fablet 2017-04-20 20:47:31 PDT
Closing bug as fixed. Please reopen if needed.