Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for options.headers to be a Headers instance with an entries method #1

Merged
merged 2 commits into from
Oct 12, 2019

Conversation

joseph-galindo
Copy link
Owner

@joseph-galindo joseph-galindo commented Oct 12, 2019

This PR is fixing the issue outlined in (developit#124). This allows consumers to use a Headers instance in their raw fetch(url, options) call for options.headers, instead of being limited to only JavaScript object literals.

The polyfill will now check if options.headers has an entries() function. If it does, it will invoke that and expect to receive an iterable object, like the Headers.entries() API does, and then iterate over that.

With this change, request headers as a Headers instance will be properly iterated and carried over correctly to the underlying XHR, instead of the current implementation which iterates on the method keys (append(), delete(), etc)

Unfortunately I could not add this support while keeping the original package under 500b, so I plan to limit these changes to my personal fork of unfetch.

I created a PR on the original repo here: developit#125
But I closed this PR since there is a strong focus on keeping bundle size low (~500b or less), and at best I was only able to add this support at ~550b.

@developit
Copy link

@joseph-galindo I think unfetch is going to get a bump up in size that should allow for exposing + consuming Headers, Response and Request.

@joseph-galindo
Copy link
Owner Author

@developit cool. I ended up working around the problem, but would be glad to open a PR against unfetch proper to support passing through Headers to the request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants