diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ServerRequest.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ServerRequest.java index 92c0b128aa..5d9c313bee 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ServerRequest.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ServerRequest.java @@ -187,13 +187,7 @@ public interface ServerRequest { * @return the attribute value */ default Optional attribute(String name) { - Map attributes = attributes(); - if (attributes.containsKey(name)) { - return Optional.of(attributes.get(name)); - } - else { - return Optional.empty(); - } + return Optional.ofNullable(attributes().get(name)); } /** @@ -350,7 +344,7 @@ public interface ServerRequest { Optional contentType(); /** - * Get the value of the required {@code Host} header. + * Get the value of the {@code Host} header, if available. *

If the header value does not contain a port, the * {@linkplain InetSocketAddress#getPort() port} in the returned address will * be {@code 0}.