-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e03d8e
commit 9ccfe3f
Showing
3 changed files
with
38 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
library/src/main/java/com/qiniu/android/utils/UrlUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |