Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
varshith257 committed Sep 29, 2024
1 parent 893ef03 commit a5a0ce7
Showing 1 changed file with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit a5a0ce7

Please sign in to comment.