Knu Knu - 1 month ago 7
Javascript Question

Polyfill to list the HTTP headers of a Header's instance

Certain versions¹ of Firefox support

Headers
but lack
Headers.prototype.entries
and
Headers.prototype.forEach
⁴.

How to go through all key/value pairs of a
Headers
' instance in an ES5-compatible² and elegant³ way on these browsers?

Could
Headers
be extended?

¹ 34–43

² no for…of

³ no brute force

⁴ supported since version 47

Answer

Before Firefox 44 (which added .keys/entries/values on Headers), there was no non-brute-force way to find out what set of headers were actually set in the object. The information simply isn't exposed anywhere.

That said, releases prior to Firefox 45 (the current ESR release) are all out of support and have known security bugs, so users should really not be using those. I don't think it's worth catering to users on those releases; they should be urged to update instead.