Skip to content

Commit 9ccfe3f

Browse files
authored
Uc query add host (#507)
1 parent 0e03d8e commit 9ccfe3f

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

library/src/main/java/com/qiniu/android/common/Config.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,13 @@ public final class Config {
6868
/**
6969
* preQuery host
7070
*/
71-
public static String preQueryHost00 = "kodo-config.qiniuapi.com";
72-
public static String preQueryHost01 = "uc.qbox.me";
73-
public static String preQueryHost02 = "api.qiniu.com";
71+
public static String preQueryHost00 = "uc.qiniuapi.com";
72+
public static String preQueryHost01 = "kodo-config.qiniuapi.com";
73+
public static String preQueryHost02 = "uc.qbox.me";
74+
public static String preQueryHost03 = "api.qiniu.com";
7475

7576
public static String[] preQueryHosts() {
76-
return new String[]{preQueryHost00, preQueryHost01, preQueryHost02};
77+
return new String[]{preQueryHost00, preQueryHost01, preQueryHost02, preQueryHost03};
7778
}
7879

7980
/**

library/src/main/java/com/qiniu/android/http/request/HttpRegionRequest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.qiniu.android.storage.UploadOptions;
1212
import com.qiniu.android.utils.LogUtil;
1313
import com.qiniu.android.utils.StringUtils;
14+
import com.qiniu.android.utils.UrlUtils;
1415

1516
import org.json.JSONObject;
1617

@@ -106,8 +107,7 @@ private void performRequest(final IUploadServer server,
106107
serverHost = config.urlConverter.convert(serverHost);
107108
}
108109

109-
String scheme = config.useHttps ? "https://" : "http://";
110-
String urlString = scheme + serverHost + (action != null ? action : "");
110+
String urlString = UrlUtils.setHostScheme(serverHost, config.useHttps) + (action != null ? action : "");
111111
final Request request = new Request(urlString, method, header, data,
112112
config.connectTimeout,
113113
config.writeTimeout,
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.qiniu.android.utils;
2+
3+
public class UrlUtils {
4+
5+
public static String removeHostScheme(String host) {
6+
if (host == null || StringUtils.isNullOrEmpty(host)) {
7+
return null;
8+
}
9+
10+
host = host.replace("http://", "");
11+
host = host.replace("https://", "");
12+
return host;
13+
}
14+
15+
16+
/**
17+
* 如果 host 包含 scheme 则优先使用 host 中包含的 scheme
18+
* 如果 host 不包含 scheme 则按照 useHttps 增加 scheme
19+
*/
20+
public static String setHostScheme(String host, boolean useHttps) {
21+
if (StringUtils.isNullOrEmpty(host)) {
22+
return null;
23+
}
24+
25+
if (host.startsWith("http://") || host.startsWith("https://") ) {
26+
return host;
27+
}
28+
29+
return (useHttps ? "https://" : "http://") + host;
30+
}
31+
}

0 commit comments

Comments
 (0)