From 27dc8b5b2cbb20a0cec6a140c3bd457fedf5028e Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Sun, 8 Oct 2023 20:12:47 +0100 Subject: [PATCH] Pass follow_redirects flag to the CORS proxy Currently redirects would be returned from the proxy, and then immediately followed by XMLHTTPRequest. The proxy now follows requests (when requested), so that should no longer happen. We should probably switch over to fetch(...) here, to allow setting follow_redirects to false, but that's a job for another day. Haha, so many web emulator related commits of late. This'll die down soon. --- .../computercraft/core/apis/http/request/THttpRequest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/projects/web/src/main/java/dan200/computercraft/core/apis/http/request/THttpRequest.java b/projects/web/src/main/java/dan200/computercraft/core/apis/http/request/THttpRequest.java index 27917c9f8..1a87e517f 100644 --- a/projects/web/src/main/java/dan200/computercraft/core/apis/http/request/THttpRequest.java +++ b/projects/web/src/main/java/dan200/computercraft/core/apis/http/request/THttpRequest.java @@ -47,6 +47,7 @@ public class THttpRequest extends Resource { private final @Nullable String postBuffer; private final HttpHeaders headers; private final boolean binary; + private final boolean followRedirects; public THttpRequest( ResourceGroup limiter, IAPIEnvironment environment, String address, @Nullable String postText, @@ -58,6 +59,7 @@ public class THttpRequest extends Resource { postBuffer = postText; this.headers = headers; this.binary = binary; + this.followRedirects = followRedirects; if (postText != null) { if (!headers.contains(HttpHeaderNames.CONTENT_TYPE)) { @@ -102,6 +104,7 @@ public class THttpRequest extends Resource { var header = iterator.next(); request.setRequestHeader(header.getKey(), header.getValue()); } + request.setRequestHeader("X-CC-Redirect", followRedirects ? "true" : "false"); request.send(postBuffer); checkClosed(); } catch (Exception e) {