Skip to content

Commit

Permalink
Avoid logging HTTP message version where it can be a hint, not an act…
Browse files Browse the repository at this point in the history
…ual protocol version
  • Loading branch information
ok2c committed Jan 7, 2025
1 parent 8c934ba commit 7ee083a
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -547,7 +545,8 @@ public void cancelled() {
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 &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {

Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7ee083a

Please sign in to comment.