Skip to content

Commit

Permalink
Update Routes.scala
Browse files Browse the repository at this point in the history
  • Loading branch information
Saturn225 authored Oct 1, 2024
1 parent 73a209b commit a17bfb1
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions zio-http/shared/src/main/scala/zio/http/Routes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -250,18 +250,18 @@ final case class Routes[-Env, +Err](routes: Chunk[zio.http.Route[Env, Err]]) { s
.fromFunctionHandler[Request] { req =>
val chunk = tree.get(req.method, req.path)
val allowedMethods = tree.getAllMethods(req.path)

req.method match {
case Method.CUSTOM(_) =>
Handler.fromZIO(ZIO.succeed(Response.status(Status.NotImplemented)))
case _ if chunk.isEmpty && allowedMethods.nonEmpty =>
Handler.fromZIO(ZIO.succeed(Response.status(Status.MethodNotAllowed)))

case _ if chunk.isEmpty && allowedMethods.isEmpty =>
Handler.notFound
case _ =>
case Method.CUSTOM(_) =>
Handler.notImplemented
case _ =>
chunk.length match {
case 0 => Handler.notFound
case 0 =>
if (allowedMethods.nonEmpty) {
val allowHeader = Header.Allow(NonEmptyChunk.fromIterableOption(allowedMethods).get)
Handler.methodNotAllowed.addHeader(allowHeader)
} else {
Handler.notFound
}
case 1 => chunk(0)
case n => // TODO: Support precomputed fallback among all chunk elements
var acc = chunk(0)
Expand Down

0 comments on commit a17bfb1

Please sign in to comment.