diff --git a/zio-http/jvm/src/main/scala/zio/http/netty/server/ServerInboundHandler.scala b/zio-http/jvm/src/main/scala/zio/http/netty/server/ServerInboundHandler.scala index 493e341921..fec613f685 100644 --- a/zio-http/jvm/src/main/scala/zio/http/netty/server/ServerInboundHandler.scala +++ b/zio-http/jvm/src/main/scala/zio/http/netty/server/ServerInboundHandler.scala @@ -114,17 +114,21 @@ private[zio] final case class ServerInboundHandler( } - private def validateHostHeader(req: Request): Boolean = { - req.headers.get("Host") match { - case Some(host) => - val isValid = host.forall(c => c.isLetterOrDigit || c == '.' || c == '-') - println(s"Host: $host, isValid: $isValid") - isValid - case None => - println("Host header missing!") - false - } + private def validateHostHeader(req: Request): Boolean = { + req.headers.get("Host") match { + case Some(host) => + val parts = host.split(":") + val isValidHost = parts(0).forall(c => c.isLetterOrDigit || c == '.' || c == '-') + val isValidPort = parts.length == 1 || (parts.length == 2 && parts(1).forall(_.isDigit)) // Allow port number + val isValid = isValidHost && isValidPort + ZIO.logDebug(s"Host: $host, isValidHost: $isValidHost, isValidPort: $isValidPort, isValid: $isValid") + isValid + case None => + ZIO.logDebug("Host header missing!") + false } +} + override def exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable): Unit = cause match {