Support URLs with path prefix (#46)

See gotify/server#127 gotify/server#122
This commit is contained in:
饺子w
2019-02-18 02:05:30 +08:00
committed by Jannis Mattheis
parent f74e79232b
commit 67daf8dc2f
4 changed files with 36 additions and 7 deletions

View File

@@ -18,6 +18,10 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import okio.Buffer;
import org.threeten.bp.OffsetDateTime;
@@ -36,6 +40,22 @@ public class Utils {
.toString();
}
public static String resolveAbsoluteUrl(String baseURL, String target) {
if (target == null) {
return null;
}
try {
URI targetUri = new URI(target);
if (targetUri.isAbsolute()) {
return target;
}
return new URL(new URL(baseURL), target).toString();
} catch (MalformedURLException | URISyntaxException e) {
Log.e("Could not resolve absolute url", e);
return target;
}
}
public static Target toDrawable(Resources resources, DrawableReceiver drawableReceiver) {
return new Target() {
@Override