Skip to content

Commit d3b349b

Browse files
committed
update okhttp3 -> okhttp4
1 parent 24bec6a commit d3b349b

File tree

9 files changed

+43
-16
lines changed

9 files changed

+43
-16
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ allprojects {
2525
Add the dependency
2626
``` groovy
2727
dependencies {
28-
implementation 'com.github.BakerJQ:RxRetroHttp:1.0.5'
28+
implementation 'com.github.BakerJQ:RxRetroHttp:1.0.10'
2929
}
3030
3131
```

README_cn.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ allprojects {
2626
在app或相应使用的module中加入
2727
``` groovy
2828
dependencies {
29-
implementation 'com.github.BakerJQ:RxRetroHttp:1.0.5'
29+
implementation 'com.github.BakerJQ:RxRetroHttp:1.0.10'
3030
}
3131
3232
```

app/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ android {
3737

3838
dependencies {
3939
implementation fileTree(dir: 'libs', include: ['*.jar'])
40-
implementation 'androidx.appcompat:appcompat:1.1.0-alpha04'
41-
implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha04'
40+
implementation 'androidx.appcompat:appcompat:1.1.0'
41+
implementation 'androidx.recyclerview:recyclerview:1.1.0-beta05'
4242
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
4343
testImplementation 'junit:junit:4.12'
44-
androidTestImplementation 'androidx.test:runner:1.1.1'
45-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
44+
androidTestImplementation 'androidx.test:runner:1.2.0'
45+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
4646

4747
implementation project(':rxretrohttp')
4848
// implementation 'com.github.BakerJQ:RxRetroHttp:1.0.3'

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ buildscript {
77
jcenter()
88
}
99
dependencies {
10-
classpath 'com.android.tools.build:gradle:3.4.1'
10+
classpath 'com.android.tools.build:gradle:3.5.1'
1111
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
1212

1313

config.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
ext {
22
versions = [
3-
'versionCode' : 5,
4-
'versionName' : '1.0.5',
3+
'versionCode' : 10,
4+
'versionName' : '1.0.10',
55

66
'compileSdk' : 28,
77
'buildTools' : '28.0.3',
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Thu Apr 18 08:52:56 CST 2019
1+
#Tue Oct 22 15:29:32 CST 2019
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip

rxretrohttp/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ android {
1919
dependencies {
2020
implementation fileTree(dir: 'libs', include: ['*.jar'])
2121
api 'com.squareup.retrofit2:retrofit:2.4.0'
22-
api 'com.squareup.okhttp3:okhttp:3.11.0'
22+
api 'com.squareup.okhttp3:okhttp:4.0.0'
2323
api 'com.squareup.okhttp3:okhttp-urlconnection:3.11.0'
24-
api 'io.reactivex.rxjava2:rxjava:2.2.3'
25-
api 'io.reactivex.rxjava2:rxandroid:2.1.0'
24+
api 'io.reactivex.rxjava2:rxjava:2.2.9'
25+
api 'io.reactivex.rxjava2:rxandroid:2.1.1'
2626
api 'com.squareup.retrofit2:converter-gson:2.4.0'
2727
api 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
2828
api 'com.trello.rxlifecycle3:rxlifecycle:3.0.0'

rxretrohttp/src/main/java/com/bakerj/rxretrohttp/converter/RetroGsonResponseBodyConverter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ class RetroGsonResponseBodyConverter<T, ApiResultType extends IApiResult> implem
3434
@Override
3535
public T convert(ResponseBody value) throws IOException {
3636
try {
37-
String response = value.string().replaceAll("\\s*|\r|\n|\t", "");
37+
// String response = value.string().replaceAll("\\s*|\r|\n|\t", "");
38+
String response = value.string();
3839
LogUtil.e("response:" + response);
3940
//parse to IApiResult based obj 解析Result
4041
ApiResultType apiResult = gson.fromJson(response, apiClass);

rxretrohttp/src/main/java/com/bakerj/rxretrohttp/interceptors/HttpLoggingInterceptor.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
import okio.Buffer;
3535
import okio.BufferedSource;
3636

37+
import static java.net.HttpURLConnection.HTTP_NOT_MODIFIED;
38+
import static java.net.HttpURLConnection.HTTP_NO_CONTENT;
39+
import static okhttp3.internal.http.StatusLine.HTTP_CONTINUE;
3740
import static okhttp3.internal.platform.Platform.INFO;
3841

3942
/**
@@ -198,7 +201,7 @@ public Response intercept(Chain chain) throws IOException {
198201
logger.log(headers.name(i) + ": " + headers.value(i));
199202
}
200203

201-
if (!logBody || !HttpHeaders.hasBody(response)) {
204+
if (!logBody || !hasBody(response)) {
202205
logger.log("<-- END HTTP");
203206
} else if (bodyEncoded(response.headers())) {
204207
logger.log("<-- END HTTP (encoded body omitted)");
@@ -236,6 +239,29 @@ private boolean bodyEncoded(Headers headers) {
236239
return contentEncoding != null && !contentEncoding.equalsIgnoreCase("identity");
237240
}
238241

242+
public static boolean hasBody(Response response) {
243+
// HEAD requests never yield a body regardless of the response headers.
244+
if (response.request().method().equals("HEAD")) {
245+
return false;
246+
}
247+
248+
int responseCode = response.code();
249+
if ((responseCode < HTTP_CONTINUE || responseCode >= 200)
250+
&& responseCode != HTTP_NO_CONTENT
251+
&& responseCode != HTTP_NOT_MODIFIED) {
252+
return true;
253+
}
254+
255+
// If the Content-Length or Transfer-Encoding headers disagree with the response code, the
256+
// response is malformed. For best compatibility, we honor the headers.
257+
if ((response.body() != null && response.body().contentLength() != -1)
258+
|| "chunked".equalsIgnoreCase(response.header("Transfer-Encoding"))) {
259+
return true;
260+
}
261+
262+
return false;
263+
}
264+
239265
public enum Level {
240266
/**
241267
* No logs.

0 commit comments

Comments
 (0)