Skip to content
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

Closed
wants to merge 3 commits into from
Closed

support change global baseUrl at runtime #1

wants to merge 3 commits into from

Conversation

LeoYu007
Copy link
Contributor

1、先判断是否有domain header,然后判断是否有设置全局url,如果都没有返回原来的request;
2、单独设置的domain header会覆盖全局的url;
3、putDomain的时候就解析url;如果url无效就抛出异常;

@@ -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);
Copy link
Owner

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
Copy link
Owner

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));
Copy link
Owner

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));

@LeoYu007 LeoYu007 closed this Jul 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants