Use InetSocketAddress#getHostString
Sometimes InetSocketAddress#getAddress#getHostAddress retuns null. In that case, call InetSocketAddress#getHostString instead. There is no performance loss since IpAddressMatcher#matches attemptsi to re-parse and resolve the address anyway. Closes gh-11888
This commit is contained in:
committed by
Josh Cummings
parent
d5354db6f4
commit
2b426872a3
@@ -48,7 +48,7 @@ public final class IpAddressServerWebExchangeMatcher implements ServerWebExchang
|
||||
public Mono<MatchResult> matches(ServerWebExchange exchange) {
|
||||
// @formatter:off
|
||||
return Mono.justOrEmpty(exchange.getRequest().getRemoteAddress())
|
||||
.map((remoteAddress) -> remoteAddress.getAddress().getHostAddress())
|
||||
.map((remoteAddress) -> remoteAddress.isUnresolved() ? remoteAddress.getHostString() : remoteAddress.getAddress().getHostAddress())
|
||||
.map(this.ipAddressMatcher::matches)
|
||||
.flatMap((matches) -> matches ? MatchResult.match() : MatchResult.notMatch())
|
||||
.switchIfEmpty(MatchResult.notMatch());
|
||||
|
||||
Reference in New Issue
Block a user