You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2025/01/07 20:19:08 UTC

(httpcomponents-client) branch 5.4.x updated: Avoid logging HTTP message version where it can be a hint, not an actual protocol version

This is an automated email from the ASF dual-hosted git repository.

olegk pushed a commit to branch 5.4.x
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git


The following commit(s) were added to refs/heads/5.4.x by this push:
     new 7ee083af4 Avoid logging HTTP message version where it can be a hint, not an actual protocol version
7ee083af4 is described below

commit 7ee083af4749c5abaeba5a5f4487b7be044ff38b
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Sat Jan 4 15:01:18 2025 +0100

    Avoid logging HTTP message version where it can be a hint, not an actual protocol version
---
 .../org/apache/hc/client5/http/impl/cache/AsyncCachingExec.java   | 7 +++----
 .../apache/hc/client5/http/impl/cache/BasicHttpAsyncCache.java    | 5 ++---
 .../org/apache/hc/client5/http/impl/cache/BasicHttpCache.java     | 5 ++---
 .../java/org/apache/hc/client5/http/impl/cache/CachingExec.java   | 7 +++----
 .../src/test/java/org/apache/hc/client5/testing/Result.java       | 6 ++----
 .../apache/hc/client5/http/impl/async/H2AsyncMainClientExec.java  | 3 +--
 .../hc/client5/http/impl/async/HttpAsyncMainClientExec.java       | 3 +--
 .../http/impl/async/LoggingAsyncClientExchangeHandler.java        | 8 +++-----
 .../org/apache/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 a6ad156c0..31ae68d65 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.HttpRequest;
 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 @@ class AsyncCachingExec extends CachingExecBase implements AsyncExecChainHandler
         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 @@ class AsyncCachingExec extends CachingExecBase implements AsyncExecChainHandler
         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 @@ class AsyncCachingExec extends CachingExecBase implements AsyncExecChainHandler
         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 7cb421795..4509a1a2c 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.HttpRequest;
 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 @@ class BasicHttpAsyncCache implements HttpAsyncCache {
     public Cancellable evictInvalidatedEntries(
             final HttpHost host, final HttpRequest request, final HttpResponse response, final FutureCallback<Boolean> 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 c47971fdd..59a509d56 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.HttpRequest;
 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 @@ class BasicHttpCache implements HttpCache {
     @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 f794fe18a..f27534ab3 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.EntityUtils;
 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 @@ class CachingExec extends CachingExecBase implements ExecChainHandler {
         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 @@ class CachingExec extends CachingExecBase implements ExecChainHandler {
         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 @@ class CachingExec extends CachingExecBase implements ExecChainHandler {
         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 104a4aedc..e49b99aee 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 @@ package org.apache.hc.client5.testing;
 
 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<T> {
 
@@ -65,13 +63,13 @@ public final class Result<T> {
     @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 563d542e3..95a3ceace 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.Header;
 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 class H2AsyncMainClientExec implements AsyncExecChainHandler {
         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 5abddaf1f..af23f7f1a 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.HttpResponse;
 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 @@ class HttpAsyncMainClientExec implements AsyncExecChainHandler {
         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 954383f4a..e2a3fb936 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.EntityDetails;
 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 @@ final class LoggingAsyncClientExchangeHandler implements AsyncClientExchangeHand
     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 @@ final class LoggingAsyncClientExchangeHandler implements AsyncClientExchangeHand
             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 @@ final class LoggingAsyncClientExchangeHandler implements AsyncClientExchangeHand
             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 5a3789cd2..f51cbb55b 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.HttpException;
 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 final class MainClientExec implements ExecChainHandler {
         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