wasmerio / winterjs

Winter is coming... ❄️
https://winterjs.org/
MIT License
3.05k stars 53 forks source link

Missing `Headers.entries` #25

Closed pi0 closed 1 year ago

pi0 commented 1 year ago

(context: from unjs/nitro#1861 tracker)


Tested runtime version: v0.1.7

MDN docs: https://developer.mozilla.org/en-US/docs/Web/API/Headers/entries

Headers.entries method seems missing.

Arshia001 commented 1 year ago

According to https://fetch.spec.whatwg.org/#headers, the headers object itself should be iterable. There is no entries method in the standard AFAICT.

The entries method as specified in the MDN docs can be added in via a simple polyfill:

Headers.prototype.entries = function() {
  return this[Symbol.iterator]();
}

We're discussing internally how we might support non-standard APIs (the standard in question being WinterCG).

syrusakbary commented 1 year ago

I've checked in Deno Deploy and Cloudflare Workers with this script:

self.addEventListener('fetch', event => {
  let headers = event.request.headers;
  event.respondWith(new Response(`typeof headers.entries == "${typeof headers.entries}"`));
})

In both cases, the response was:

typeof headers.entries == "function"

Which means that both Cloudflare Workers and Deno Deploy had this implemented. We should follow up to see if it should be in the spec

syrusakbary commented 1 year ago

We made the decision to follow Cloudflare Workers, and implement Headers.entries

Arshia001 commented 1 year ago

I've added the method in, will be available with the next version.

pi0 commented 1 year ago

Thanks!