diff --git a/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HttpRequestUrl.java b/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HttpRequestUrl.java index 2a85bdee8..3d86354da 100644 --- a/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HttpRequestUrl.java +++ b/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HttpRequestUrl.java @@ -6,6 +6,8 @@ public class HttpRequestUrl { + private static final StringBuilder requestBuilder = new StringBuilder(); + private HttpRequestUrl() { } @@ -22,20 +24,20 @@ private HttpRequestUrl() { * @return the adapted resource url */ public static String buildResourceUrl(@NonNull String host, String resourceUrl, int querySize, boolean offline) { + requestBuilder.delete(0, requestBuilder.length()); + requestBuilder.append(resourceUrl); if (isValidMapboxEndpoint(host)) { if (querySize == 0) { - resourceUrl = resourceUrl + "?"; + requestBuilder.append("?"); } else { - resourceUrl = resourceUrl + "&"; + requestBuilder.append("&"); } - // Only add SKU token to requests not tagged as "offline" usage. if (offline) { - resourceUrl = resourceUrl + "offline=true"; - } else { - resourceUrl = resourceUrl + "sku=" + Mapbox.getSkuToken(); + requestBuilder.append("offline=true&"); } + requestBuilder.append("sku=").append(Mapbox.getSkuToken()); } - return resourceUrl; + return requestBuilder.toString(); } /** diff --git a/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/module/http/HttpRequestUrlTest.kt b/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/module/http/HttpRequestUrlTest.kt index 5db7b0b0f..a50870f23 100644 --- a/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/module/http/HttpRequestUrlTest.kt +++ b/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/module/http/HttpRequestUrlTest.kt @@ -20,14 +20,14 @@ class HttpRequestUrlTest { @Test fun testOfflineFlagMapboxCom() { - val expected = "http://mapbox.com/path/of/no/return.pbf?offline=true" + val expected = "http://mapbox.com/path/of/no/return.pbf?offline=true&sku=foobar" val actual = HttpRequestUrl.buildResourceUrl("mapbox.com", "http://mapbox.com/path/of/no/return.pbf", 0, true) assertEquals(expected, actual) } @Test fun testOfflineFlagMapboxCn() { - val expected = "http://mapbox.cn/path/of/no/return.pbf?offline=true" + val expected = "http://mapbox.cn/path/of/no/return.pbf?offline=true&sku=foobar" val actual = HttpRequestUrl.buildResourceUrl("mapbox.cn", "http://mapbox.cn/path/of/no/return.pbf", 0, true) assertEquals(expected, actual) }