Skip to content

Commit

Permalink
Uc query add host (#507)
Browse files Browse the repository at this point in the history
  • Loading branch information
YangSen-qn authored Nov 23, 2023
1 parent 0e03d8e commit 9ccfe3f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
9 changes: 5 additions & 4 deletions library/src/main/java/com/qiniu/android/common/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,13 @@ public final class Config {
/**
* preQuery host
*/
public static String preQueryHost00 = "kodo-config.qiniuapi.com";
public static String preQueryHost01 = "uc.qbox.me";
public static String preQueryHost02 = "api.qiniu.com";
public static String preQueryHost00 = "uc.qiniuapi.com";
public static String preQueryHost01 = "kodo-config.qiniuapi.com";
public static String preQueryHost02 = "uc.qbox.me";
public static String preQueryHost03 = "api.qiniu.com";

public static String[] preQueryHosts() {
return new String[]{preQueryHost00, preQueryHost01, preQueryHost02};
return new String[]{preQueryHost00, preQueryHost01, preQueryHost02, preQueryHost03};
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.qiniu.android.storage.UploadOptions;
import com.qiniu.android.utils.LogUtil;
import com.qiniu.android.utils.StringUtils;
import com.qiniu.android.utils.UrlUtils;

import org.json.JSONObject;

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

String scheme = config.useHttps ? "https://" : "http://";
String urlString = scheme + serverHost + (action != null ? action : "");
String urlString = UrlUtils.setHostScheme(serverHost, config.useHttps) + (action != null ? action : "");
final Request request = new Request(urlString, method, header, data,
config.connectTimeout,
config.writeTimeout,
Expand Down
31 changes: 31 additions & 0 deletions library/src/main/java/com/qiniu/android/utils/UrlUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.qiniu.android.utils;

public class UrlUtils {

public static String removeHostScheme(String host) {
if (host == null || StringUtils.isNullOrEmpty(host)) {
return null;
}

host = host.replace("http://", "");
host = host.replace("https://", "");
return host;
}


/**
* 如果 host 包含 scheme 则优先使用 host 中包含的 scheme
* 如果 host 不包含 scheme 则按照 useHttps 增加 scheme
*/
public static String setHostScheme(String host, boolean useHttps) {
if (StringUtils.isNullOrEmpty(host)) {
return null;
}

if (host.startsWith("http://") || host.startsWith("https://") ) {
return host;
}

return (useHttps ? "https://" : "http://") + host;
}
}

0 comments on commit 9ccfe3f

Please sign in to comment.