Exclude query from URI in WebClient checkpoints
Closes gh-31992
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -212,7 +212,7 @@ final class DefaultClientResponseBuilder implements ClientResponse.Builder {
|
||||
|
||||
return new DefaultClientResponse(httpResponse, this.strategies,
|
||||
this.originalResponse != null ? this.originalResponse.logPrefix() : "",
|
||||
this.request.getMethod() + " " + this.request.getURI(),
|
||||
WebClientUtils.getRequestDescription(this.request.getMethod(), this.request.getURI()),
|
||||
() -> this.request);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.web.reactive.function.client;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.ArrayList;
|
||||
@@ -54,7 +53,6 @@ import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.reactive.function.BodyExtractor;
|
||||
import org.springframework.web.reactive.function.BodyInserter;
|
||||
import org.springframework.web.reactive.function.BodyInserters;
|
||||
@@ -457,7 +455,9 @@ final class DefaultWebClient implements WebClient {
|
||||
observationContext.setRequest(request);
|
||||
Mono<ClientResponse> responseMono = filterFunction.apply(exchangeFunction)
|
||||
.exchange(request)
|
||||
.checkpoint("Request to " + this.httpMethod.name() + " " + this.uri + " [DefaultWebClient]")
|
||||
.checkpoint("Request to " +
|
||||
WebClientUtils.getRequestDescription(request.method(), request.url()) +
|
||||
" [DefaultWebClient]")
|
||||
.switchIfEmpty(NO_HTTP_CLIENT_RESPONSE_ERROR);
|
||||
if (this.contextModifier != null) {
|
||||
responseMono = responseMono.contextWrite(this.contextModifier);
|
||||
@@ -693,24 +693,13 @@ final class DefaultWebClient implements WebClient {
|
||||
}
|
||||
Mono<T> result = exMono.flatMap(Mono::error);
|
||||
return result.checkpoint(statusCode + " from " +
|
||||
this.httpMethod + " " + getUriToLog(this.uri) + " [DefaultWebClient]");
|
||||
WebClientUtils.getRequestDescription(this.httpMethod, this.uri) +
|
||||
" [DefaultWebClient]");
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static URI getUriToLog(URI uri) {
|
||||
if (StringUtils.hasText(uri.getQuery())) {
|
||||
try {
|
||||
uri = new URI(uri.getScheme(), null, uri.getHost(), uri.getPort(), uri.getPath(), null, null);
|
||||
}
|
||||
catch (URISyntaxException ex) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
return uri;
|
||||
}
|
||||
|
||||
|
||||
private static class StatusHandler {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -97,8 +97,8 @@ public class WebClientResponseException extends WebClientException {
|
||||
}
|
||||
|
||||
private static String initMessage(HttpStatusCode status, String reasonPhrase, @Nullable HttpRequest request) {
|
||||
return status.value() + " " + reasonPhrase +
|
||||
(request != null ? " from " + request.getMethod() + " " + request.getURI() : "");
|
||||
return status.value() + " " + reasonPhrase + (request != null ?
|
||||
" from " + WebClientUtils.getRequestDescription(request.getMethod(), request.getURI()) : "");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.web.reactive.function.client;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@@ -24,7 +26,9 @@ import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.core.codec.CodecException;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Internal methods shared between {@link DefaultWebClient} and
|
||||
@@ -64,4 +68,20 @@ abstract class WebClientUtils {
|
||||
new ResponseEntity<>(list, response.headers().asHttpHeaders(), response.statusCode()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a String representation of the request details for logging purposes.
|
||||
* @since 6.0.16
|
||||
*/
|
||||
public static String getRequestDescription(HttpMethod httpMethod, URI uri) {
|
||||
if (StringUtils.hasText(uri.getQuery())) {
|
||||
try {
|
||||
uri = new URI(uri.getScheme(), null, uri.getHost(), uri.getPort(), uri.getPath(), null, null);
|
||||
}
|
||||
catch (URISyntaxException ex) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
return httpMethod.name() + " " + uri;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user