public class SuperUrlParser extends java.lang.Object implements UrlParser
RetrofitUrlManager.putDomain(String, String) 方法的 Url 替换掉
但如果突然有一小部分的 Url 只想将 "https://www.github.com/wiki" (PathSize = 1) 替换掉, 后面的 pathSegment '/part' 想被保留下来
这时项目中就出现了多个 PathSize 不同的需要被替换的 BaseUrl
使用高级模式实现这种需求略显麻烦, 所以我创建了超级模式, 让每一个 Url 都可以随意指定不同的 BaseUrl (PathSize 自己定) 作为被替换的基准 使 RetrofitUrlManager 可以从容应对各种复杂的需求
超级模式也需要手动开启, 但与高级模式不同的是, 开启超级模式并不需要调用 API, 只需要在 Url 中加入 RetrofitUrlManager.IDENTIFICATION_PATH_SIZE + PathSize
替换规则如下:
1.
旧 URL 地址为 https://www.github.com/wiki/part#baseurl_path_size=1, #baseurl_path_size=1 表示其中 BaseUrl 为 https://www.github.com/wiki
您调用 RetrofitUrlManager.putDomain(String, String)方法传入的 URL 地址是 https://www.google.com/api
经过本解析器解析后生成的新 URL 地址为 http://www.google.com/api/part
2.
旧 URL 地址为 https://www.github.com/wiki/part#baseurl_path_size=1, #baseurl_path_size=1 表示其中 BaseUrl 为 https://www.github.com/wiki
您调用 RetrofitUrlManager.putDomain(String, String)方法传入的 URL 地址是 https://www.google.com
经过本解析器解析后生成的新 URL 地址为 http://www.google.com/part
3.
旧 URL 地址为 https://www.github.com/wiki/part#baseurl_path_size=0, #baseurl_path_size=0 表示其中 BaseUrl 为 https://www.github.com
您调用 RetrofitUrlManager.putDomain(String, String)方法传入的 URL 地址是 https://www.google.com/api
经过本解析器解析后生成的新 URL 地址为 http://www.google.com/api/wiki/part
4.
旧 URL 地址为 https://www.github.com/wiki/part/issues/1#baseurl_path_size=3, #baseurl_path_size=3 表示其中 BaseUrl 为 https://www.github.com/wiki/part/issues
您调用 RetrofitUrlManager.putDomain(String, String)方法传入的 URL 地址是 https://www.google.com/api
经过本解析器解析后生成的新 URL 地址为 http://www.google.com/api/1
| Constructor and Description |
|---|
SuperUrlParser() |
| Modifier and Type | Method and Description |
|---|---|
void |
init(RetrofitUrlManager retrofitUrlManager)
这里可以做一些初始化操作
|
okhttp3.HttpUrl |
parseUrl(okhttp3.HttpUrl domainUrl,
okhttp3.HttpUrl url)
|
public void init(RetrofitUrlManager retrofitUrlManager)
UrlParserinit in interface UrlParserretrofitUrlManager - RetrofitUrlManager