From 7ee083af4749c5abaeba5a5f4487b7be044ff38b Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Sat, 4 Jan 2025 15:01:18 +0100 Subject: [PATCH] Avoid logging HTTP message version where it can be a hint, not an actual protocol version --- .../hc/client5/http/impl/cache/AsyncCachingExec.java | 7 +++---- .../hc/client5/http/impl/cache/BasicHttpAsyncCache.java | 5 ++--- .../apache/hc/client5/http/impl/cache/BasicHttpCache.java | 5 ++--- .../apache/hc/client5/http/impl/cache/CachingExec.java | 7 +++---- .../test/java/org/apache/hc/client5/testing/Result.java | 6 ++---- .../hc/client5/http/impl/async/H2AsyncMainClientExec.java | 3 +-- .../client5/http/impl/async/HttpAsyncMainClientExec.java | 3 +-- .../impl/async/LoggingAsyncClientExchangeHandler.java | 8 +++----- .../hc/client5/http/impl/classic/MainClientExec.java | 3 +-- 9 files changed, 18 insertions(+), 29 deletions(-) diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AsyncCachingExec.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AsyncCachingExec.java index a6ad156c05..31ae68d656 100644 --- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AsyncCachingExec.java +++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AsyncCachingExec.java @@ -70,7 +70,6 @@ import org.apache.hc.core5.http.HttpResponse; import org.apache.hc.core5.http.HttpStatus; import org.apache.hc.core5.http.impl.BasicEntityDetails; -import org.apache.hc.core5.http.message.RequestLine; import org.apache.hc.core5.http.nio.AsyncDataConsumer; import org.apache.hc.core5.http.nio.AsyncEntityProducer; import org.apache.hc.core5.http.nio.CapacityChannel; @@ -242,7 +241,7 @@ public void doExecute( final CancellableDependency operation = scope.cancellableDependency; if (LOG.isDebugEnabled()) { - LOG.debug("{} request via cache: {}", exchangeId, new RequestLine(request)); + LOG.debug("{} request via cache: {} {}", exchangeId, request.getMethod(), request.getRequestUri()); } context.setCacheResponseStatus(CacheResponseStatus.CACHE_MISS); @@ -727,7 +726,7 @@ private void handleCacheHit( final String exchangeId = scope.exchangeId; if (LOG.isDebugEnabled()) { - LOG.debug("{} cache hit: {}", exchangeId, new RequestLine(request)); + LOG.debug("{} cache hit: {} {}", exchangeId, request.getMethod(), request.getRequestUri()); } context.setCacheResponseStatus(CacheResponseStatus.CACHE_HIT); @@ -1150,7 +1149,7 @@ private void handleCacheMiss( final String exchangeId = scope.exchangeId; if (LOG.isDebugEnabled()) { - LOG.debug("{} cache miss: {}", exchangeId, new RequestLine(request)); + LOG.debug("{} cache miss: {} {}", exchangeId, request.getMethod(), request.getRequestUri()); } cacheMisses.getAndIncrement(); diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/BasicHttpAsyncCache.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/BasicHttpAsyncCache.java index 7cb4217956..4509a1a2c8 100644 --- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/BasicHttpAsyncCache.java +++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/BasicHttpAsyncCache.java @@ -57,8 +57,6 @@ import org.apache.hc.core5.http.HttpResponse; import org.apache.hc.core5.http.HttpStatus; import org.apache.hc.core5.http.Method; -import org.apache.hc.core5.http.message.RequestLine; -import org.apache.hc.core5.http.message.StatusLine; import org.apache.hc.core5.util.ByteArrayBuffer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -547,7 +545,8 @@ public void cancelled() { public Cancellable evictInvalidatedEntries( final HttpHost host, final HttpRequest request, final HttpResponse response, final FutureCallback callback) { if (LOG.isDebugEnabled()) { - LOG.debug("Flush cache entries invalidated by exchange: {}; {} -> {}", host, new RequestLine(request), new StatusLine(response)); + LOG.debug("Flush cache entries invalidated by exchange: {}; {} {} -> {}", + host, request.getMethod(), request.getRequestUri(), response.getCode()); } final int status = response.getCode(); if (status >= HttpStatus.SC_SUCCESS && status < HttpStatus.SC_CLIENT_ERROR && diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/BasicHttpCache.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/BasicHttpCache.java index c47971fdd5..59a509d568 100644 --- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/BasicHttpCache.java +++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/BasicHttpCache.java @@ -50,8 +50,6 @@ import org.apache.hc.core5.http.HttpResponse; import org.apache.hc.core5.http.HttpStatus; import org.apache.hc.core5.http.Method; -import org.apache.hc.core5.http.message.RequestLine; -import org.apache.hc.core5.http.message.StatusLine; import org.apache.hc.core5.util.ByteArrayBuffer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -343,7 +341,8 @@ private void evict(final String rootKey, final HttpResponse response) { @Override public void evictInvalidatedEntries(final HttpHost host, final HttpRequest request, final HttpResponse response) { if (LOG.isDebugEnabled()) { - LOG.debug("Evict cache entries invalidated by exchange: {}; {} -> {}", host, new RequestLine(request), new StatusLine(response)); + LOG.debug("Evict cache entries invalidated by exchange: {}; {} {} -> {}", + host, request.getMethod(), request.getRequestUri(), response.getCode()); } final int status = response.getCode(); if (status >= HttpStatus.SC_SUCCESS && status < HttpStatus.SC_CLIENT_ERROR && diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java index f794fe18a7..f27534ab34 100644 --- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java +++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java @@ -65,7 +65,6 @@ import org.apache.hc.core5.http.io.entity.StringEntity; import org.apache.hc.core5.http.io.support.ClassicRequestBuilder; import org.apache.hc.core5.http.message.BasicClassicHttpResponse; -import org.apache.hc.core5.http.message.RequestLine; import org.apache.hc.core5.net.URIAuthority; import org.apache.hc.core5.util.Args; import org.apache.hc.core5.util.ByteArrayBuffer; @@ -147,7 +146,7 @@ ClassicHttpResponse doExecute( final HttpCacheContext context = HttpCacheContext.cast(scope.clientContext); if (LOG.isDebugEnabled()) { - LOG.debug("{} request via cache: {}", exchangeId, new RequestLine(request)); + LOG.debug("{} request via cache: {} {}", exchangeId, request.getMethod(), request.getRequestUri()); } context.setCacheResponseStatus(CacheResponseStatus.CACHE_MISS); @@ -247,7 +246,7 @@ private ClassicHttpResponse handleCacheHit( final HttpCacheContext context = HttpCacheContext.cast(scope.clientContext); if (LOG.isDebugEnabled()) { - LOG.debug("{} cache hit: {}", exchangeId, new RequestLine(request)); + LOG.debug("{} cache hit: {} {}", exchangeId, request.getMethod(), request.getRequestUri()); } context.setCacheResponseStatus(CacheResponseStatus.CACHE_HIT); @@ -571,7 +570,7 @@ private ClassicHttpResponse handleCacheMiss( final String exchangeId = scope.exchangeId; if (LOG.isDebugEnabled()) { - LOG.debug("{} cache miss: {}", exchangeId, new RequestLine(request)); + LOG.debug("{} cache miss: {} {}", exchangeId, request.getMethod(), request.getRequestUri()); } cacheMisses.getAndIncrement(); diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/Result.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/Result.java index 104a4aedc1..e49b99aee9 100644 --- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/Result.java +++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/Result.java @@ -28,8 +28,6 @@ import org.apache.hc.core5.http.HttpRequest; import org.apache.hc.core5.http.HttpResponse; -import org.apache.hc.core5.http.message.RequestLine; -import org.apache.hc.core5.http.message.StatusLine; public final class Result { @@ -65,13 +63,13 @@ public boolean isOK() { @Override public String toString() { final StringBuilder buf = new StringBuilder(); - buf.append(new RequestLine(request)); + buf.append(request.getMethod()).append(" ").append(request.getRequestUri()); buf.append(" -> "); if (exception != null) { buf.append("NOK: ").append(exception); } else { if (response != null) { - buf.append("OK: ").append(new StatusLine(response)); + buf.append("OK: ").append(response.getCode()); } } return buf.toString(); diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/H2AsyncMainClientExec.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/H2AsyncMainClientExec.java index 563d542e31..95a3ceacea 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/H2AsyncMainClientExec.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/H2AsyncMainClientExec.java @@ -47,7 +47,6 @@ import org.apache.hc.core5.http.HttpException; import org.apache.hc.core5.http.HttpRequest; import org.apache.hc.core5.http.HttpResponse; -import org.apache.hc.core5.http.message.RequestLine; import org.apache.hc.core5.http.nio.AsyncClientExchangeHandler; import org.apache.hc.core5.http.nio.AsyncDataConsumer; import org.apache.hc.core5.http.nio.AsyncEntityProducer; @@ -93,7 +92,7 @@ public void execute( final AsyncExecRuntime execRuntime = scope.execRuntime; if (LOG.isDebugEnabled()) { - LOG.debug("{} executing {}", exchangeId, new RequestLine(request)); + LOG.debug("{} executing {} {}", exchangeId, request.getMethod(), request.getRequestUri()); } final AsyncClientExchangeHandler internalExchangeHandler = new AsyncClientExchangeHandler() { diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncMainClientExec.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncMainClientExec.java index 5abddaf1f2..af23f7f1af 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncMainClientExec.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncMainClientExec.java @@ -55,7 +55,6 @@ import org.apache.hc.core5.http.HttpStatus; import org.apache.hc.core5.http.ProtocolException; import org.apache.hc.core5.http.ProtocolVersion; -import org.apache.hc.core5.http.message.RequestLine; import org.apache.hc.core5.http.nio.AsyncClientExchangeHandler; import org.apache.hc.core5.http.nio.AsyncDataConsumer; import org.apache.hc.core5.http.nio.AsyncEntityProducer; @@ -110,7 +109,7 @@ public void execute( final AsyncExecRuntime execRuntime = scope.execRuntime; if (LOG.isDebugEnabled()) { - LOG.debug("{} executing {}", exchangeId, new RequestLine(request)); + LOG.debug("{} executing {} {}", exchangeId, request.getMethod(), request.getRequestUri()); } final AtomicInteger messageCountDown = new AtomicInteger(2); diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/LoggingAsyncClientExchangeHandler.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/LoggingAsyncClientExchangeHandler.java index 954383f4a3..e2a3fb936f 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/LoggingAsyncClientExchangeHandler.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/LoggingAsyncClientExchangeHandler.java @@ -34,8 +34,6 @@ import org.apache.hc.core5.http.Header; import org.apache.hc.core5.http.HttpException; import org.apache.hc.core5.http.HttpResponse; -import org.apache.hc.core5.http.message.RequestLine; -import org.apache.hc.core5.http.message.StatusLine; import org.apache.hc.core5.http.nio.AsyncClientExchangeHandler; import org.apache.hc.core5.http.nio.CapacityChannel; import org.apache.hc.core5.http.nio.DataStreamChannel; @@ -70,7 +68,7 @@ public void releaseResources() { public void produceRequest(final RequestChannel channel, final HttpContext context) throws HttpException, IOException { handler.produceRequest((request, entityDetails, context1) -> { if (log.isDebugEnabled()) { - log.debug("{} send request {}, {}", exchangeId, new RequestLine(request), + log.debug("{} send request {} {}, {}", exchangeId, request.getMethod(), request.getRequestUri(), entityDetails != null ? "entity len " + entityDetails.getContentLength() : "null entity"); } channel.sendRequest(request, entityDetails, context1); @@ -126,7 +124,7 @@ public void consumeInformation( final HttpResponse response, final HttpContext context) throws HttpException, IOException { if (log.isDebugEnabled()) { - log.debug("{}: information response {}", exchangeId, new StatusLine(response)); + log.debug("{}: information response {}", exchangeId, response.getCode()); } handler.consumeInformation(response, context); } @@ -137,7 +135,7 @@ public void consumeResponse( final EntityDetails entityDetails, final HttpContext context) throws HttpException, IOException { if (log.isDebugEnabled()) { - log.debug("{}: consume response {}, {}", exchangeId, new StatusLine(response), entityDetails != null ? "entity len " + entityDetails.getContentLength() : " null entity"); + log.debug("{}: consume response {}, {}", exchangeId, response.getCode(), entityDetails != null ? "entity len " + entityDetails.getContentLength() : " null entity"); } handler.consumeResponse(response, entityDetails, context); } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/MainClientExec.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/MainClientExec.java index 5a3789cd25..f51cbb55bd 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/MainClientExec.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/MainClientExec.java @@ -51,7 +51,6 @@ import org.apache.hc.core5.http.HttpStatus; import org.apache.hc.core5.http.ProtocolException; import org.apache.hc.core5.http.ProtocolVersion; -import org.apache.hc.core5.http.message.RequestLine; import org.apache.hc.core5.http.protocol.HttpProcessor; import org.apache.hc.core5.io.CloseMode; import org.apache.hc.core5.util.Args; @@ -109,7 +108,7 @@ public ClassicHttpResponse execute( final ExecRuntime execRuntime = scope.execRuntime; if (LOG.isDebugEnabled()) { - LOG.debug("{} executing {}", exchangeId, new RequestLine(request)); + LOG.debug("{} executing {} {}", exchangeId, request.getMethod(), request.getRequestUri()); } try { // Run request protocol interceptors