Skip to content

Commit bef7aba

Browse files
authored
Update Apache HttpClient5 to 5.4.1 (#1453)
Update Apache HttpClient5 to 5.4.2
1 parent f8fce2d commit bef7aba

File tree

6 files changed

+17
-6
lines changed

6 files changed

+17
-6
lines changed

instrumentation/httpclient5/pom.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
<main.basedir>${project.basedir}/../..</main.basedir>
2525

2626
<!-- To obey the integration tests, we need to use the version >= 5.2 -->
27-
<!-- TODO: pinned due to timeouts on 5.4.x on brave.httpclient5.ITTracingCachingH2ClientBuilder.cacheControl -->
28-
<httpclient5.version>5.3.1</httpclient5.version>
27+
<httpclient5.version>5.4.1</httpclient5.version>
2928
</properties>
3029

3130
<dependencies>

instrumentation/httpclient5/src/main/java/brave/httpclient5/HttpClientUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ static boolean isLocalCached(HttpContext context, Span span) {
5858
if (!HAS_CLIENT_CACHE_SUPPORT) {
5959
return false;
6060
}
61-
boolean cacheHit = CacheResponseStatus.CACHE_HIT == context.getAttribute(
62-
HttpCacheContext.CACHE_RESPONSE_STATUS);
61+
final HttpCacheContext cacheContext = HttpCacheContext.cast(context);
62+
final boolean cacheHit = CacheResponseStatus.CACHE_HIT == cacheContext.getCacheResponseStatus();
6363
if (cacheHit) {
6464
span.tag("http.cache_hit", "");
6565
}

instrumentation/httpclient5/src/main/java/brave/httpclient5/TracingHttpAsyncClient.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.io.IOException;
1010
import java.util.concurrent.Future;
1111
import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
12+
import org.apache.hc.client5.http.protocol.HttpClientContext;
1213
import org.apache.hc.core5.concurrent.FutureCallback;
1314
import org.apache.hc.core5.function.Supplier;
1415
import org.apache.hc.core5.http.HttpHost;
@@ -58,15 +59,17 @@ protected <T> Future<T> doExecute(
5859
HandlerFactory<AsyncPushConsumer> pushHandlerFactory, HttpContext context,
5960
FutureCallback<T> callback) {
6061
TraceContext invocationContext = currentTraceContext.get();
62+
63+
final HttpClientContext clientContext = HttpClientContext.castOrCreate(context);
6164
if (invocationContext != null) {
62-
context.setAttribute(TraceContext.class.getName(), invocationContext);
65+
clientContext.setAttribute(TraceContext.class.getName(), invocationContext);
6366
}
6467

6568
if (callback != null && invocationContext != null) {
6669
callback = new TraceContextFutureCallback<>(callback, currentTraceContext, invocationContext);
6770
}
6871

69-
return delegate.execute(target, requestProducer, responseConsumer, pushHandlerFactory, context,
72+
return delegate.execute(target, requestProducer, responseConsumer, pushHandlerFactory, clientContext,
7073
callback);
7174
}
7275

instrumentation/httpclient5/src/test/java/brave/httpclient5/ITTracingCachingH2ClientBuilder.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
import brave.propagation.SamplingFlags;
1010
import brave.propagation.TraceContext;
1111
import java.io.IOException;
12+
import java.time.ZonedDateTime;
1213
import java.util.Arrays;
1314
import okhttp3.mockwebserver.MockResponse;
1415
import org.apache.hc.client5.http.impl.async.H2AsyncClientBuilder;
1516
import org.apache.hc.client5.http.impl.cache.CachingH2AsyncClientBuilder;
17+
import org.apache.hc.client5.http.utils.DateUtils;
1618
import org.junit.jupiter.api.Test;
1719

1820
import static brave.Span.Kind.CLIENT;
@@ -33,6 +35,7 @@ protected H2AsyncClientBuilder newClientBuilder() {
3335
server.enqueue(new MockResponse()
3436
.addHeader("Content-Type", "text/plain")
3537
.addHeader("Cache-Control", "max-age=600, stale-while-revalidate=1200")
38+
.addHeader("Date", DateUtils.FORMATTER_RFC1123.format(ZonedDateTime.now()))
3639
.setBody("Hello"));
3740

3841
TraceContext parent = newTraceContext(SamplingFlags.SAMPLED);

instrumentation/httpclient5/src/test/java/brave/httpclient5/ITTracingCachingHttpAsyncClientBuilder.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
import brave.propagation.SamplingFlags;
1010
import brave.propagation.TraceContext;
1111
import java.io.IOException;
12+
import java.time.ZonedDateTime;
1213
import java.util.Arrays;
1314
import okhttp3.mockwebserver.MockResponse;
1415
import org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder;
1516
import org.apache.hc.client5.http.impl.cache.CachingHttpAsyncClientBuilder;
17+
import org.apache.hc.client5.http.utils.DateUtils;
1618
import org.junit.jupiter.api.Test;
1719

1820
import static brave.Span.Kind.CLIENT;
@@ -32,6 +34,7 @@ protected HttpAsyncClientBuilder newClientBuilder() {
3234
server.enqueue(new MockResponse()
3335
.addHeader("Content-Type", "text/plain")
3436
.addHeader("Cache-Control", "max-age=600, stale-while-revalidate=1200")
37+
.addHeader("Date", DateUtils.FORMATTER_RFC1123.format(ZonedDateTime.now()))
3538
.setBody("Hello"));
3639

3740
TraceContext parent = newTraceContext(SamplingFlags.SAMPLED);

instrumentation/httpclient5/src/test/java/brave/httpclient5/ITTracingCachingHttpClientBuilder.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
import brave.propagation.SamplingFlags;
1010
import brave.propagation.TraceContext;
1111
import java.io.IOException;
12+
import java.time.ZonedDateTime;
1213
import java.util.Arrays;
1314
import okhttp3.mockwebserver.MockResponse;
1415
import org.apache.hc.client5.http.impl.cache.CachingHttpClientBuilder;
1516
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
17+
import org.apache.hc.client5.http.utils.DateUtils;
1618
import org.junit.jupiter.api.Test;
1719

1820
import static brave.Span.Kind.CLIENT;
@@ -32,6 +34,7 @@ protected CloseableHttpClient newClient(int port) {
3234
server.enqueue(new MockResponse()
3335
.addHeader("Content-Type", "text/plain")
3436
.addHeader("Cache-Control", "max-age=600, stale-while-revalidate=1200")
37+
.addHeader("Date", DateUtils.FORMATTER_RFC1123.format(ZonedDateTime.now()))
3538
.setBody("Hello"));
3639

3740
TraceContext parent = newTraceContext(SamplingFlags.SAMPLED);

0 commit comments

Comments
 (0)