Skip to content

Commit 739a204

Browse files
committed
* http_client: update okhttp to 5.1.0
Signed-off-by: neo <1100909+neowu@users.noreply.github.com>
1 parent 2b89854 commit 739a204

File tree

4 files changed

+6
-19
lines changed

4 files changed

+6
-19
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
### 9.2.3 (7/2/2025 - )
44

55
* db: support postgres enum type
6+
* http_client: update okhttp to 5.1.0
67

78
### 9.2.2 (5/21/2025 - 6/26/2025)
89

build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ apply(plugin = "project")
77

88
subprojects {
99
group = "core.framework"
10-
version = "9.2.3-b0"
10+
version = "9.2.3"
1111
repositories {
1212
maven {
1313
url = uri("https://neowu.github.io/maven-repo/")
@@ -36,7 +36,7 @@ project("core-ng") {
3636
implementation("org.javassist:javassist:3.30.2-GA")
3737
implementation("com.fasterxml.jackson.module:jackson-module-afterburner:${jacksonVersion}")
3838
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:${jacksonVersion}")
39-
implementation("com.squareup.okhttp3:okhttp:4.12.0")
39+
implementation("com.squareup.okhttp3:okhttp:5.1.0")
4040
implementation("io.undertow:undertow-core:2.3.18.Final")
4141
implementation("org.apache.kafka:kafka-clients:4.0.0") {
4242
exclude("org.xerial.snappy")

core-ng/src/main/java/core/framework/internal/http/HTTPClientImpl.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import okhttp3.Request;
1919
import okhttp3.RequestBody;
2020
import okhttp3.Response;
21-
import okhttp3.ResponseBody;
2221
import org.slf4j.Logger;
2322
import org.slf4j.LoggerFactory;
2423

@@ -158,9 +157,7 @@ private byte[] body(Response httpResponse, int statusCode) throws IOException {
158157
// refer to https://tools.ietf.org/html/rfc7230#section-3.3.2, with 204, server won't send body and content-length, hence no need to read it, and body will be quietly closed by response.close()
159158
body = new byte[0];
160159
} else {
161-
ResponseBody responseBody = httpResponse.body();
162-
if (responseBody == null) throw new Error("unexpected response body"); // refer to okhttp3.Response.body(), call.execute always return non-null body except for cachedResponse/networkResponse
163-
body = responseBody.bytes();
160+
body = httpResponse.body().bytes();
164161
}
165162
return body;
166163
}

core-ng/src/main/java/core/framework/internal/http/RetryInterceptor.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
import okhttp3.Interceptor;
88
import okhttp3.Request;
99
import okhttp3.Response;
10-
import okhttp3.ResponseBody;
11-
import okhttp3.internal.connection.RouteException;
1210
import okhttp3.internal.http2.ConnectionShutdownException;
1311
import okhttp3.internal.http2.ErrorCode;
1412
import okhttp3.internal.http2.StreamResetException;
@@ -22,7 +20,6 @@
2220
import java.time.Duration;
2321

2422
import static core.framework.log.Markers.errorCode;
25-
import static okhttp3.internal.Util.closeQuietly;
2623

2724
/**
2825
* @author neo
@@ -47,11 +44,11 @@ public Response intercept(Chain chain) throws IOException {
4744
int statusCode = response.code();
4845
if (shouldRetry(statusCode, attempts)) { // do not check call.isCanceled(), RetryAndFollowUpInterceptor already checked and throw exception
4946
logger.warn(errorCode("HTTP_REQUEST_FAILED"), "http request failed, retry soon, responseStatus={}, uri={}", statusCode, uri(request));
50-
closeResponseBody(response);
47+
response.close();
5148
} else {
5249
return response;
5350
}
54-
} catch (IOException | RouteException e) {
51+
} catch (IOException e) {
5552
if (shouldRetry(chain.call().isCanceled(), request.method(), attempts, e)) {
5653
logger.warn(errorCode("HTTP_REQUEST_FAILED"), "http request failed, retry soon, uri={}, error={}", uri(request), e.getMessage(), e);
5754
} else {
@@ -72,13 +69,6 @@ String uri(Request request) {
7269
return request.url().newBuilder().query(null).build().toString();
7370
}
7471

75-
// response.close asserts body not null, refer to Response.close()
76-
// RetryAndFollowUpInterceptor also closes body directly
77-
private void closeResponseBody(Response response) {
78-
ResponseBody body = response.body();
79-
if (body != null) closeQuietly(body);
80-
}
81-
8272
boolean shouldRetry(int statusCode, int attempts) {
8373
if (statusCode == HTTPStatus.SERVICE_UNAVAILABLE.code || statusCode == HTTPStatus.TOO_MANY_REQUESTS.code) {
8474
if (attempts >= maxRetries) return false;
@@ -93,7 +83,6 @@ boolean shouldRetry(boolean canceled, String method, int attempts, Exception e)
9383
if (attempts >= maxRetries) return false;
9484
if (!withinMaxProcessTime(attempts)) return false;
9585

96-
if (e instanceof RouteException) return true; // if it's route failure, then request is not sent yet
9786
if (e instanceof ConnectionShutdownException) return true; // refer to RetryAndFollowUpInterceptor -> requestSendStarted = e !is ConnectionShutdownException
9887

9988
// only not retry on POST if request sent

0 commit comments

Comments
 (0)