This commit is contained in:
Dante
2026-05-21 23:40:20 -07:00
parent 3e2915dff7
commit 877a69d844
5737 changed files with 29796 additions and 1589684 deletions

View File

@ -30,6 +30,7 @@ import haxe.io.Bytes;
class HttpJs extends haxe.http.HttpBase {
public var async:Bool;
public var withCredentials:Bool;
public var responseHeaders:Map<String, String>;
var req:js.html.XMLHttpRequest;
@ -53,6 +54,7 @@ class HttpJs extends haxe.http.HttpBase {
public override function request(?post:Bool) {
this.responseAsString = null;
this.responseBytes = null;
this.responseHeaders = null;
var r = req = js.Browser.createXMLHttpRequest();
var onreadystatechange = function(_) {
if (r.readyState != 4)
@ -73,6 +75,21 @@ class HttpJs extends haxe.http.HttpBase {
onStatus(s);
if (s != null && s >= 200 && s < 400) {
req = null;
// split headers and remove the last \r\n\r\n
var headers = r.getAllResponseHeaders().split('\r\n');
headers = headers.filter(h -> h != '');
// store response headers
responseHeaders = new haxe.ds.StringMap();
for (hline in headers) {
var a = hline.split(": ");
var hname = a.shift();
var hval = if (a.length == 1) a[0] else a.join(": ");
hval = StringTools.ltrim(StringTools.rtrim(hval));
responseHeaders.set(hname, hval);
}
success(Bytes.ofData(r.response));
} else if (s == null || (s == 0 && r.response == null)) {
req = null;