-
Notifications
You must be signed in to change notification settings - Fork 310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support change global baseUrl at runtime #1
Conversation
@@ -146,8 +146,8 @@ public void accept(Throwable throwable) throws Exception { | |||
findViewById(R.id.bt_request3).setOnClickListener(new View.OnClickListener() { | |||
@Override | |||
public void onClick(View v) { | |||
String url = RetrofitUrlManager.getInstance().fetchDomain(DOUBAN_DOMAIN_NAME); | |||
if (!url.equals(mUrl3.getText().toString())) { //可以在 App 运行时随意切换某个接口的 BaseUrl | |||
HttpUrl url = RetrofitUrlManager.getInstance().fetchDomain(GANK_DOMAIN_NAME); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fetchDomain(DOUBAN_DOMAIN_NAME);
String url = RetrofitUrlManager.getInstance().fetchDomain(GITHUB_DOMAIN_NAME); | ||
if (!url.equals(mUrl1.getText().toString())) { //可以在 App 运行时随意切换某个接口的 BaseUrl | ||
HttpUrl url = RetrofitUrlManager.getInstance().fetchDomain(GITHUB_DOMAIN_NAME); | ||
if (url == null || !url.equals(HttpUrl.parse(mUrl1.getText().toString()))) { //可以在 App 运行时随意切换某个接口的 BaseUrl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (url == null || !url.toString().equals(mUrl1.getText().toString())) 少HttpUrl.parse一次节约性能
* 存放 Domain 的映射关系 | ||
* | ||
* @param domainName | ||
* @param domainUrl | ||
*/ | ||
public void putDomain(String domainName, String domainUrl) { | ||
synchronized (mDomainNameHub) { | ||
mDomainNameHub.put(domainName, domainUrl); | ||
mDomainNameHub.put(domainName, mUrlParser.parseUrl(domainUrl)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mDomainNameHub.put(domainName, Utils.checkUrl(domainUrl));
1、先判断是否有domain header,然后判断是否有设置全局url,如果都没有返回原来的request;
2、单独设置的domain header会覆盖全局的url;
3、putDomain的时候就解析url;如果url无效就抛出异常;