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 8c80527 commit 893ef03
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/http-conformance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,7 @@ jobs:
# run: |

# sed -i -e 's+(project in file("./zio-http"))+(project in file("./zio-http"))' build.sbt
- name: Compile
run: sbt clean compile
- name: Run HTTP Conformance Tests
run: sbt "project zioHttpJVM" "testOnly zio.http.ConformanceSpec"
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private[zio] final case class ServerInboundHandler(
} else {
val req = makeZioRequest(ctx, jReq)
if (!validateHostHeader(req)) {
// Return 400 Bad Request if Host validation fails
// Validation failed, return 400 Bad Request
attemptFastWrite(ctx, req.method, Response.status(Status.BadRequest))
releaseRequest()
} else {
Expand All @@ -115,18 +115,15 @@ private[zio] final case class ServerInboundHandler(
}

private def validateHostHeader(req: Request): Boolean = {
var hostCount = 0
var validHost = true

req.headers.foreach { header =>
if (header.headerName.equalsIgnoreCase("Host")) {
hostCount += 1
if (hostCount > 1 || !header.renderedValue.forall(c => c.isLetterOrDigit || c == '.' || c == '-')) {
validHost = false
}
}
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
}
hostCount == 1 && validHost
}

override def exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable): Unit =
Expand Down

0 comments on commit 893ef03

Please sign in to comment.