RESOLVED FIXED 168043
[Fetch API] fetch fails when undefined is passed as headers
https://bugs.webkit.org/show_bug.cgi?id=168043
Summary [Fetch API] fetch fails when undefined is passed as headers
Torjus
Reported 2017-02-09 01:34:44 PST
When explicitly passing `undefined` to the `headers` option of `fetch()`, the promise is rejected with 'TypeError: undefined is not an object'. To reproduce, run `fetch('/my-awesome-api', { headers: undefined })`. Both Chrome and Firefox will accept explicitly passing `{ headers: undefined }`. As the fetch API has been available in other browsers for quite some time now, I think passing `undefined` should be supported, as existing libraries or application may break when doesn't fall back to using a polyfill.
Attachments
Patch (3.76 KB, patch)
2017-02-10 08:22 PST, youenn fablet
no flags
youenn fablet
Comment 1 2017-02-10 08:01:41 PST
Hi Torjus and thanks for the feedback. Your understanding seems indeed correct.
youenn fablet
Comment 2 2017-02-10 08:22:40 PST
Geoffrey Garen
Comment 3 2017-02-10 08:58:34 PST
Comment on attachment 301160 [details] Patch r=me What should happen if 'headers' is null? How about a string or a number? You should add tests for those cases.
Chris Dumez
Comment 4 2017-02-10 09:18:04 PST
Comment on attachment 301160 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=301160&action=review > Source/WebCore/Modules/fetch/FetchInternals.js:33 > + if (headersInit === @undefined) What about null?
youenn fablet
Comment 5 2017-02-10 10:32:22 PST
We need IDL tests for all of them I guess. Checking with Chris, null should be fine (empty header), other values should not.
Chris Dumez
Comment 6 2017-02-10 10:36:22 PST
(In reply to comment #5) > We need IDL tests for all of them I guess. > Checking with Chris, null should be fine (empty header), other values should > not. https://heycam.github.io/webidl/#es-union (Step 3.2.) then https://heycam.github.io/webidl/#es-record (Step 2) So passing null or undefined should behave the same here.
Chris Dumez
Comment 7 2017-02-10 10:37:42 PST
(In reply to comment #6) > (In reply to comment #5) > > We need IDL tests for all of them I guess. > > Checking with Chris, null should be fine (empty header), other values should > > not. > > https://heycam.github.io/webidl/#es-union (Step 3.2.) > then > https://heycam.github.io/webidl/#es-record (Step 2) > > So passing null or undefined should behave the same here. I would expect other non-object types to throw a TypeError based on https://heycam.github.io/webidl/#es-union (Step 17)
youenn fablet
Comment 8 2017-02-10 15:43:48 PST
(In reply to comment #6) > (In reply to comment #5) > > We need IDL tests for all of them I guess. > > Checking with Chris, null should be fine (empty header), other values should > > not. > > https://heycam.github.io/webidl/#es-union (Step 3.2.) > then > https://heycam.github.io/webidl/#es-record (Step 2) > > So passing null or undefined should behave the same here. This feels a bit odd though in that case to have the same behavior. Somehow {headers: undefined} means that there is no headers in the dictionary and we should reuse the RequestInfo headers if any. {headers: null} might mean to create a request without any header. Let's get more time for fetch+WebIDL spec to stabilise on that.
youenn fablet
Comment 9 2017-02-10 15:51:34 PST
Landing this patch as is since it is a step in the right direction. We will probably complement it with additional patches.
WebKit Commit Bot
Comment 10 2017-02-10 15:55:06 PST
Comment on attachment 301160 [details] Patch Clearing flags on attachment: 301160 Committed r212162: <http://trac.webkit.org/changeset/212162>
WebKit Commit Bot
Comment 11 2017-02-10 15:55:11 PST
All reviewed patches have been landed. Closing bug.
Alexey Proskuryakov
Comment 12 2017-03-28 17:32:23 PDT
*** Bug 169970 has been marked as a duplicate of this bug. ***
youenn fablet
Comment 13 2017-05-08 22:08:55 PDT
(In reply to youenn fablet from comment #8) > (In reply to comment #6) > > (In reply to comment #5) > > > We need IDL tests for all of them I guess. > > > Checking with Chris, null should be fine (empty header), other values should > > > not. > > > > https://heycam.github.io/webidl/#es-union (Step 3.2.) > > then > > https://heycam.github.io/webidl/#es-record (Step 2) > > > > So passing null or undefined should behave the same here. WebIDL spec has changed and we should now throw in case of null passed to a Record.
Note You need to log in before you can comment on or make changes to this bug.