How to use Headers and Cookie API in JS

Hi, I assume on browser we can access/read current page’s header information using following API:
js.html.Headers - Haxe 4.3.4 API

Additionally, I’m trying to find how to use Cookie API in Haxe/JS:
js.Cookie - Haxe 4.3.4 API

Currently, I can read browser headers in following way - but this do not gives me ability to access the value in Headers way but string:

var htmlWindow = cast(, Window);
var req = new XMLHttpRequest();'GET', htmlWindow.document.location.href, true);
req.onload = function() {
	var headers = req.getAllResponseHeaders().toLowerCase();

Same way, I can access cookies by writing following, but that do not able me to access the value in Cookie API way:


Any help would be very appreciating. Thank you.

Here’s what I use.

import js.Cookie;
var ptreferrer:String = Cookie.exists("ptreferrer") ? Cookie.get("ptreferrer") : "";

//or to set it:

The docs for js.html.Headers mention that it is part of the Fetch API.

Based on that, I would guess you can only use js.html.Headers if you make your requests using js.html.Window.fetch() instead of XMLHttpRequest.

Thanks to both @Confidant and @joshtynjala - both the suggested ways worked perfectly! Thank you, once again. :slightly_smiling_face: