From d8baea2a6607ee81f5bde824c27aceb295beb4d5 Mon Sep 17 00:00:00 2001 From: Logan Perkins Date: Thu, 2 Dec 2021 13:03:42 -0800 Subject: [PATCH 1/3] Filter the :Status pseudo-header out when fetching all headers for fetch API --- .../rptools/maptool/client/ui/htmlframe/MTXMLHttpRequest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/rptools/maptool/client/ui/htmlframe/MTXMLHttpRequest.java b/src/main/java/net/rptools/maptool/client/ui/htmlframe/MTXMLHttpRequest.java index 18d81c158c..ab5acd7b3e 100644 --- a/src/main/java/net/rptools/maptool/client/ui/htmlframe/MTXMLHttpRequest.java +++ b/src/main/java/net/rptools/maptool/client/ui/htmlframe/MTXMLHttpRequest.java @@ -56,7 +56,9 @@ public void _getResponseHeaders(JSObject jheaders) { responseHeaders.forEach( (key, value) -> { - jheaders.setMember(key, value); + if (!key.equals(":Status")) { + jheaders.setMember(key, value); + } }); } From 0efc78d01b3f8b169ed8b37912c1354f3f796284 Mon Sep 17 00:00:00 2001 From: Logan Perkins Date: Thu, 2 Dec 2021 13:04:30 -0800 Subject: [PATCH 2/3] Use UTF_8 for lib://URI responses --- .../net/rptools/maptool/model/library/url/RequestHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/rptools/maptool/model/library/url/RequestHandler.java b/src/main/java/net/rptools/maptool/model/library/url/RequestHandler.java index 66fa2a1e27..8e090ff997 100644 --- a/src/main/java/net/rptools/maptool/model/library/url/RequestHandler.java +++ b/src/main/java/net/rptools/maptool/model/library/url/RequestHandler.java @@ -121,7 +121,7 @@ public static CompletableFuture processRequest( } responseHeaders.put(":Status", "200"); try { - c.complete(new String(stream.readAllBytes(), StandardCharsets.UTF_16)); + c.complete(new String(stream.readAllBytes(), StandardCharsets.UTF_8)); return c; } catch (IOException e) { responseHeaders.put(":Status", "500 Internal Exception"); From 1e48ba2dae7023c2ec8218d28038ec15c0d0bf6b Mon Sep 17 00:00:00 2001 From: Logan Perkins Date: Thu, 2 Dec 2021 13:04:53 -0800 Subject: [PATCH 3/3] Make `fetch` async and handle request.text body returning a promise. --- .../maptool/client/html5/javascript/XMLHttpRequest.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/resources/net/rptools/maptool/client/html5/javascript/XMLHttpRequest.js b/src/main/resources/net/rptools/maptool/client/html5/javascript/XMLHttpRequest.js index 5328dfc1c7..15f8ae0325 100644 --- a/src/main/resources/net/rptools/maptool/client/html5/javascript/XMLHttpRequest.js +++ b/src/main/resources/net/rptools/maptool/client/html5/javascript/XMLHttpRequest.js @@ -107,7 +107,7 @@ class XMLHttpRequest { } -function fetch(target, optionObject) { +async function fetch(target, optionObject) { let request; if (target instanceof Request) { request = target; @@ -126,7 +126,8 @@ function fetch(target, optionObject) { for (let header of request.headers) { x.setRequestHeader(header[0], header[1]) } - let body = request.text(); + let body = await request.text(); + let _resolve; let _reject;