Commit 6fba477d authored by Andy Wilkinson's avatar Andy Wilkinson

Remove redundant handling of a null exchange from WebFluxTags.uri()

Closes gh-14504
parent 6020cb67
...@@ -40,8 +40,6 @@ public final class WebFluxTags { ...@@ -40,8 +40,6 @@ public final class WebFluxTags {
private static final Tag URI_ROOT = Tag.of("uri", "root"); private static final Tag URI_ROOT = Tag.of("uri", "root");
private static final Tag URI_UNKNOWN = Tag.of("uri", "UNKNOWN");
private static final Tag EXCEPTION_NONE = Tag.of("exception", "None"); private static final Tag EXCEPTION_NONE = Tag.of("exception", "None");
private WebFluxTags() { private WebFluxTags() {
...@@ -80,26 +78,23 @@ public final class WebFluxTags { ...@@ -80,26 +78,23 @@ public final class WebFluxTags {
* @return the uri tag derived from the exchange * @return the uri tag derived from the exchange
*/ */
public static Tag uri(ServerWebExchange exchange) { public static Tag uri(ServerWebExchange exchange) {
if (exchange != null) { PathPattern pathPattern = exchange
PathPattern pathPattern = exchange .getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE); if (pathPattern != null) {
if (pathPattern != null) { return Tag.of("uri", pathPattern.getPatternString());
return Tag.of("uri", pathPattern.getPatternString()); }
} HttpStatus status = exchange.getResponse().getStatusCode();
HttpStatus status = exchange.getResponse().getStatusCode(); if (status != null && status.is3xxRedirection()) {
if (status != null && status.is3xxRedirection()) { return URI_REDIRECTION;
return URI_REDIRECTION; }
} if (status != null && status.equals(HttpStatus.NOT_FOUND)) {
if (status != null && status.equals(HttpStatus.NOT_FOUND)) { return URI_NOT_FOUND;
return URI_NOT_FOUND; }
} String path = exchange.getRequest().getPath().value();
String path = exchange.getRequest().getPath().value(); if (path.isEmpty()) {
if (path.isEmpty()) { return URI_ROOT;
return URI_ROOT;
}
return Tag.of("uri", path);
} }
return URI_UNKNOWN; return Tag.of("uri", path);
} }
/** /**
......
...@@ -78,12 +78,6 @@ public class WebFluxTagsTests { ...@@ -78,12 +78,6 @@ public class WebFluxTagsTests {
assertThat(tag.getValue()).isEqualTo("root"); assertThat(tag.getValue()).isEqualTo("root");
} }
@Test
public void uriTagIsUnknownWhenRequestIsNull() {
Tag tag = WebFluxTags.uri(null);
assertThat(tag.getValue()).isEqualTo("UNKNOWN");
}
@Test @Test
public void methodTagToleratesNonStandardHttpMethods() { public void methodTagToleratesNonStandardHttpMethods() {
ServerWebExchange exchange = mock(ServerWebExchange.class); ServerWebExchange exchange = mock(ServerWebExchange.class);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment