Skip to content

Commit 3d21e39

Browse files
committed
Refactor getRequestDescription with early return in WebClientUtils
Reduce nesting in query-string handling by returning early when rawQuery is null, improving readability without changing behavior. Signed-off-by: 박동윤 (Park Dong-Yun) <ehddbs7458@gmail.com>
1 parent 5c747a4 commit 3d21e39

1 file changed

Lines changed: 22 additions & 20 deletions

File tree

  • spring-webflux/src/main/java/org/springframework/web/reactive/function/client

spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClientUtils.java

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -72,30 +72,32 @@ public static <T> Mono<ResponseEntity<List<T>>> mapToEntityList(ClientResponse r
7272
* @since 6.0.16
7373
*/
7474
public static String getRequestDescription(HttpMethod httpMethod, URI uri) {
75-
if (uri.getRawQuery() != null) {
76-
StringBuilder sb = new StringBuilder();
77-
if (uri.getScheme() != null) {
78-
sb.append(uri.getScheme()).append(':');
75+
if (uri.getRawQuery() == null) {
76+
return httpMethod.name() + " " + uri;
77+
}
78+
StringBuilder sb = new StringBuilder();
79+
if (uri.getScheme() != null) {
80+
sb.append(uri.getScheme()).append(':');
81+
}
82+
if (uri.getHost() != null) {
83+
sb.append("//");
84+
String host = uri.getHost();
85+
// IPv6 handling
86+
if (host.indexOf(':') >= 0 && !host.startsWith("[") && !host.endsWith("]")) {
87+
sb.append('[').append(host).append(']');
7988
}
80-
if (uri.getHost() != null) {
81-
sb.append("//");
82-
String host = uri.getHost();
83-
if (host.indexOf(':') >= 0 && !host.startsWith("[") && !host.endsWith("]")) {
84-
sb.append('[').append(host).append(']');
85-
}
86-
else {
87-
sb.append(host);
88-
}
89-
if (uri.getPort() != -1) {
90-
sb.append(':').append(uri.getPort());
91-
}
89+
else {
90+
sb.append(host);
9291
}
93-
if (uri.getPath() != null) {
94-
sb.append(uri.getPath());
92+
93+
if (uri.getPort() != -1) {
94+
sb.append(':').append(uri.getPort());
9595
}
96-
return httpMethod.name() + " " + sb;
9796
}
98-
return httpMethod.name() + " " + uri;
97+
if (uri.getPath() != null) {
98+
sb.append(uri.getPath());
99+
}
100+
return httpMethod.name() + " " + sb;
99101
}
100102

101103
}

0 commit comments

Comments
 (0)