From 15fb9fd7ce037a3eeedaa58f8e92d0cbc28118ab Mon Sep 17 00:00:00 2001 From: Adam Warski Date: Tue, 12 Dec 2023 08:11:29 +0100 Subject: [PATCH] When calculating the client ip, allow the possibility of the address to be null (#3389) --- core/src/main/scala/sttp/tapir/Tapir.scala | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/src/main/scala/sttp/tapir/Tapir.scala b/core/src/main/scala/sttp/tapir/Tapir.scala index 3b4439c3ed..3366cb1b9a 100644 --- a/core/src/main/scala/sttp/tapir/Tapir.scala +++ b/core/src/main/scala/sttp/tapir/Tapir.scala @@ -480,7 +480,13 @@ trait TapirComputedInputs { this: Tapir => .flatMap(_.split(",").headOption) .orElse(request.header("Remote-Address")) .orElse(request.header("X-Real-Ip")) - .orElse(request.connectionInfo.remote.flatMap(a => Option(a.getAddress.getHostAddress))) + .orElse { + for { + r <- request.connectionInfo.remote + a <- Option(r.getAddress) + ha <- Option(a.getHostAddress) + } yield ha + } ) def isWebSocket: EndpointInput[Boolean] =