From efa4e981da44726d8e436b271be72b7aaf24fbf8 Mon Sep 17 00:00:00 2001 From: crschnick Date: Tue, 9 Sep 2025 01:08:23 +0000 Subject: [PATCH] Rotate service URLs [stage] [arm] --- dist/changelog/18.6_incremental.md | 1 + .../base/service/AbstractServiceStore.java | 10 +---- .../base/service/ServiceAddressRotation.java | 38 +++++++++++++++++++ version | 2 +- 4 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 ext/base/src/main/java/io/xpipe/ext/base/service/ServiceAddressRotation.java diff --git a/dist/changelog/18.6_incremental.md b/dist/changelog/18.6_incremental.md index b0942300e..5abbe464a 100644 --- a/dist/changelog/18.6_incremental.md +++ b/dist/changelog/18.6_incremental.md @@ -1,2 +1,3 @@ - Fix some types connection entries being moved to default category after their configuration was edited - Fix bitwarden login issues when using custom server +- Rotate service URLs to avoid browser cache issues when running multiple services on localhost diff --git a/ext/base/src/main/java/io/xpipe/ext/base/service/AbstractServiceStore.java b/ext/base/src/main/java/io/xpipe/ext/base/service/AbstractServiceStore.java index 160947371..734cca334 100644 --- a/ext/base/src/main/java/io/xpipe/ext/base/service/AbstractServiceStore.java +++ b/ext/base/src/main/java/io/xpipe/ext/base/service/AbstractServiceStore.java @@ -40,15 +40,7 @@ public abstract class AbstractServiceStore implements SingletonSessionStore replacedUrls = new HashMap<>(); + private static int counter = 0; + private static final String[] aliases = new String[]{ "localhost", "127.0.0.1" }; + + private static String getRotatedLocalhost(String url) { + if (!url.startsWith("localhost")) { + return url; + } + + if (replacedUrls.containsKey(url)) { + return replacedUrls.get(url); + } + + var alias = aliases[counter++ % aliases.length]; + var replaced = url.replace("localhost", alias); + replacedUrls.put(url, replaced); + return replaced; + } + + public static String getRotatedAddress(AbstractServiceStore serviceStore) { + var s = serviceStore.getSession(); + if (s == null) { + var host = serviceStore.getHost().getStore().getTunnelHostName() != null + ? serviceStore.getHost().getStore().getTunnelHostName() + : "localhost"; + return getRotatedLocalhost(host + ":" + serviceStore.getRemotePort()); + } + + return getRotatedLocalhost("localhost:" + s.getLocalPort()); + } +} diff --git a/version b/version index a05c6ad07..67b0fedab 100644 --- a/version +++ b/version @@ -1 +1 @@ -18.6-1 +18.6-2