mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-23 21:33:19 +00:00
fix(android): keep a sign-in proxy's page out of the offline copy
The copy now only stores answers that come from the server itself and no HTML in place of a script or stylesheet, so a proxy's login page no longer replaces the stored UI.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user