Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

fix(android): keep a sign-in proxy's page out of the offline copy

Maurice4fead3259d10
diff --git a/client/android/app/src/main/java/com/liketrek/trek/TrekShellPlugin.java b/client/android/app/src/main/java/com/liketrek/trek/TrekShellPlugin.java
index 9d609a081..b88ddfb42 100644
--- a/client/android/app/src/main/java/com/liketrek/trek/TrekShellPlugin.java
+++ b/client/android/app/src/main/java/com/liketrek/trek/TrekShellPlugin.java
@@ -572,7 +572,10 @@ public class TrekShellPlugin extends Plugin {
}).start();
}
- /** A file of the server's UI, or null: only a 200 counts, and the page only as HTML. */
+ /**
+ * A file of the server's UI, or null: only a 200 from the server itself
+ * counts, the page only as HTML and a file only as something else.
+ */
private static byte[] download(String server, String path, String wantType) {
java.net.HttpURLConnection connection = null;
try {
@@ -584,8 +587,11 @@ public class TrekShellPlugin extends Plugin {
connection.setInstanceFollowRedirects(true);
if (wantType != null) connection.setRequestProperty("Accept", wantType);
if (connection.getResponseCode() != 200) return null;
+ java.net.URL landed = connection.getURL();
+ if (!landed.getProtocol().equals(base.getProtocol()) || !landed.getHost().equalsIgnoreCase(base.getHost()) || portOf(landed) != portOf(base)) return null;
String type = connection.getContentType();
if (wantType != null && (type == null || !type.startsWith(wantType))) return null;
+ if (wantType == null && type != null && type.startsWith("text/html") && !path.endsWith(".html")) return null;
try (java.io.InputStream in = connection.getInputStream()) {
java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream();
byte[] buffer = new byte[16384];
@@ -599,6 +605,10 @@ public class TrekShellPlugin extends Plugin {
}
}
+ private static int portOf(java.net.URL url) {
+ return url.getPort() == -1 ? url.getDefaultPort() : url.getPort();
+ }
+
/**
* The address screen found the server out of reach: with a copy of its UI
* the app restarts on that instead (TrekOfflineShell), the same way it