Make appbase_domain work with https URLs.
Also refactored code to be more easily testable and added some tests.
This commit is contained in:
@@ -542,7 +542,7 @@ public class Application
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check if we're overriding the domain in the appbase
|
// check if we're overriding the domain in the appbase
|
||||||
_appbase = overrideAppbase(_appbase);
|
_appbase = SysProps.overrideAppbase(_appbase);
|
||||||
|
|
||||||
// make sure there's a trailing slash
|
// make sure there's a trailing slash
|
||||||
if (!_appbase.endsWith("/")) {
|
if (!_appbase.endsWith("/")) {
|
||||||
@@ -567,7 +567,7 @@ public class Application
|
|||||||
if (latest.startsWith(_appbase)) {
|
if (latest.startsWith(_appbase)) {
|
||||||
latest = _appbase + latest.substring(_appbase.length());
|
latest = _appbase + latest.substring(_appbase.length());
|
||||||
} else {
|
} else {
|
||||||
latest = replaceDomain(latest);
|
latest = SysProps.replaceDomain(latest);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
_latest = new URL(latest);
|
_latest = new URL(latest);
|
||||||
@@ -1809,31 +1809,6 @@ public class Application
|
|||||||
return cookie.toString();
|
return cookie.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Applies {@code appbase_override} or {@code appbase_domain} if they are set.
|
|
||||||
*/
|
|
||||||
protected String overrideAppbase (String appbase) {
|
|
||||||
String appbaseOverride = SysProps.appbaseOverride();
|
|
||||||
if (appbaseOverride != null) {
|
|
||||||
return appbaseOverride;
|
|
||||||
} else {
|
|
||||||
return replaceDomain(appbase);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If appbase_domain property is set, replace the domain on the provided string.
|
|
||||||
*/
|
|
||||||
protected String replaceDomain (String appbase)
|
|
||||||
{
|
|
||||||
String appbaseDomain = SysProps.appbaseDomain();
|
|
||||||
if (appbaseDomain != null) {
|
|
||||||
Matcher m = Pattern.compile("(http://[^/]+)(.*)").matcher(appbase);
|
|
||||||
appbase = m.replaceAll(appbaseDomain + "$2");
|
|
||||||
}
|
|
||||||
return appbase;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encodes a path for use in a URL.
|
* Encodes a path for use in a URL.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -5,6 +5,9 @@
|
|||||||
|
|
||||||
package com.threerings.getdown.data;
|
package com.threerings.getdown.data;
|
||||||
|
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import com.threerings.getdown.util.VersionUtil;
|
import com.threerings.getdown.util.VersionUtil;
|
||||||
import com.threerings.getdown.launcher.Getdown;
|
import com.threerings.getdown.launcher.Getdown;
|
||||||
|
|
||||||
@@ -136,4 +139,29 @@ public class SysProps
|
|||||||
"Regexp '" + propRegex + "' does not match '" + verstr + "' (from " + propName + ")");
|
"Regexp '" + propRegex + "' does not match '" + verstr + "' (from " + propName + ")");
|
||||||
return vers;
|
return vers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applies {@code appbase_override} or {@code appbase_domain} if they are set.
|
||||||
|
*/
|
||||||
|
public static String overrideAppbase (String appbase) {
|
||||||
|
String appbaseOverride = appbaseOverride();
|
||||||
|
if (appbaseOverride != null) {
|
||||||
|
return appbaseOverride;
|
||||||
|
} else {
|
||||||
|
return replaceDomain(appbase);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If appbase_domain property is set, replace the domain on the provided string.
|
||||||
|
*/
|
||||||
|
public static String replaceDomain (String appbase)
|
||||||
|
{
|
||||||
|
String appbaseDomain = appbaseDomain();
|
||||||
|
if (appbaseDomain != null) {
|
||||||
|
Matcher m = Pattern.compile("(https?://[^/]+)(.*)").matcher(appbase);
|
||||||
|
appbase = m.replaceAll(appbaseDomain + "$2");
|
||||||
|
}
|
||||||
|
return appbase;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
//
|
||||||
|
// Getdown - application installer, patcher and launcher
|
||||||
|
// Copyright (C) 2004-2016 Getdown authors
|
||||||
|
// https://github.com/threerings/getdown/blob/master/LICENSE
|
||||||
|
|
||||||
|
package com.threerings.getdown.data;
|
||||||
|
|
||||||
|
import org.junit.*;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
public class SysPropsTest {
|
||||||
|
|
||||||
|
@After public void clearProps () {
|
||||||
|
System.clearProperty("appbase_domain");
|
||||||
|
System.clearProperty("appbase_override");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String[] APPBASES = {
|
||||||
|
"http://foobar.com/myapp",
|
||||||
|
"https://foobar.com/myapp",
|
||||||
|
"http://foobar.com:8080/myapp",
|
||||||
|
"https://foobar.com:8080/myapp"
|
||||||
|
};
|
||||||
|
|
||||||
|
@Test public void testAppbaseDomain () {
|
||||||
|
System.setProperty("appbase_domain", "https://barbaz.com");
|
||||||
|
for (String appbase : APPBASES) {
|
||||||
|
assertEquals("https://barbaz.com/myapp", SysProps.overrideAppbase(appbase));
|
||||||
|
}
|
||||||
|
System.setProperty("appbase_domain", "http://barbaz.com");
|
||||||
|
for (String appbase : APPBASES) {
|
||||||
|
assertEquals("http://barbaz.com/myapp", SysProps.overrideAppbase(appbase));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test public void testAppbaseOverride () {
|
||||||
|
System.setProperty("appbase_override", "https://barbaz.com/newapp");
|
||||||
|
for (String appbase : APPBASES) {
|
||||||
|
assertEquals("https://barbaz.com/newapp", SysProps.overrideAppbase(appbase));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user