-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from yale8848/dev
Dev
- Loading branch information
Showing
14 changed files
with
119 additions
and
22 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
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
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
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
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
43 changes: 43 additions & 0 deletions
43
...itcachelib/src/main/java/ren/yale/android/retrofitcachelib/intercept/MockInterceptor.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,43 @@ | ||
package ren.yale.android.retrofitcachelib.intercept; | ||
|
||
import java.io.IOException; | ||
|
||
import okhttp3.Interceptor; | ||
import okhttp3.Request; | ||
import okhttp3.Response; | ||
import ren.yale.android.retrofitcachelib.util.LogUtil; | ||
|
||
/** | ||
* Created by yale on 2019/7/24. | ||
*/ | ||
public class MockInterceptor extends BaseInterceptor implements Interceptor { | ||
|
||
|
||
@Override | ||
public Response intercept(Chain chain) throws IOException { | ||
Request request = chain.request(); | ||
Response mockResponse = mockResponse(chain); | ||
if (mockResponse!=null){ | ||
return mockResponse; | ||
} | ||
String mockUrl = mockUrl(chain); | ||
if (mockUrl!=null){ | ||
LogUtil.d("get data from mock url: "+mockUrl); | ||
request = request.newBuilder().url(mockUrl).header(KEY_HEADER_PRE_URL,request.url().toString()) | ||
.build(); | ||
} | ||
Response response = chain.proceed(request); | ||
int code = response.code(); | ||
if ( code == 504){ | ||
response = chain.proceed(chain.request()); | ||
} | ||
if(response.networkResponse()!=null){ | ||
LogUtil.d("get data from net"); | ||
} else | ||
if (response.cacheResponse()!=null){ | ||
LogUtil.d("get data from cache"); | ||
} | ||
|
||
return response; | ||
} | ||
} |
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
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
43 changes: 43 additions & 0 deletions
43
...elibrx2/src/main/java/ren/yale/android/retrofitcachelibrx2/intercept/MockInterceptor.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,43 @@ | ||
package ren.yale.android.retrofitcachelibrx2.intercept; | ||
|
||
import java.io.IOException; | ||
|
||
import okhttp3.Interceptor; | ||
import okhttp3.Request; | ||
import okhttp3.Response; | ||
import ren.yale.android.retrofitcachelibrx2.util.LogUtil; | ||
|
||
/** | ||
* Created by yale on 2019/7/24. | ||
*/ | ||
public class MockInterceptor extends BaseInterceptor implements Interceptor { | ||
|
||
|
||
@Override | ||
public Response intercept(Chain chain) throws IOException { | ||
Request request = chain.request(); | ||
Response mockResponse = mockResponse(chain); | ||
if (mockResponse!=null){ | ||
return mockResponse; | ||
} | ||
String mockUrl = mockUrl(chain); | ||
if (mockUrl!=null){ | ||
LogUtil.d("get data from mock url: "+mockUrl); | ||
request = request.newBuilder().url(mockUrl).header(KEY_HEADER_PRE_URL,request.url().toString()) | ||
.build(); | ||
} | ||
Response response = chain.proceed(request); | ||
int code = response.code(); | ||
if ( code == 504){ | ||
response = chain.proceed(chain.request()); | ||
} | ||
if(response.networkResponse()!=null){ | ||
LogUtil.d("get data from net"); | ||
} else | ||
if (response.cacheResponse()!=null){ | ||
LogUtil.d("get data from cache"); | ||
} | ||
|
||
return response; | ||
} | ||
} |