From fbd7ab859831fec838548cf9634482e73fc91938 Mon Sep 17 00:00:00 2001 From: Vamshi Maskuri <117595548+varshith257@users.noreply.github.com> Date: Fri, 27 Sep 2024 15:17:25 +0530 Subject: [PATCH] fmt --- .../jvm/src/test/scala/zio/http/StaticServerSpec.scala | 2 +- zio-http/shared/src/main/scala/zio/http/Routes.scala | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/zio-http/jvm/src/test/scala/zio/http/StaticServerSpec.scala b/zio-http/jvm/src/test/scala/zio/http/StaticServerSpec.scala index d397ec9af9..506df04490 100644 --- a/zio-http/jvm/src/test/scala/zio/http/StaticServerSpec.scala +++ b/zio-http/jvm/src/test/scala/zio/http/StaticServerSpec.scala @@ -88,7 +88,7 @@ object StaticServerSpec extends RoutesRunnableSpec { } }, test("404 response ") { - checkAll(methodGenWithoutHEAD) { method => + { method => val actual = status(method, Path.root / "A") assertZIO(actual)(equalTo(Status.NotFound)) } diff --git a/zio-http/shared/src/main/scala/zio/http/Routes.scala b/zio-http/shared/src/main/scala/zio/http/Routes.scala index 544d2ab36b..aac5601794 100644 --- a/zio-http/shared/src/main/scala/zio/http/Routes.scala +++ b/zio-http/shared/src/main/scala/zio/http/Routes.scala @@ -252,13 +252,10 @@ final case class Routes[-Env, +Err](routes: Chunk[zio.http.Route[Env, Err]]) { s val allowedMethods = tree.getAllMethods(req.path) chunk.length match { case 0 => - if (allowedMethods.isEmpty) { - // Case 1: Path doesn't exist at all -> 404 Not Found - Handler.notFound + if (!allowedMethods.contains(req.method) && allowedMethods.nonEmpty) { + Handler.status(Status.MethodNotAllowed) } else if (!Method.knownMethods.contains(req.method)) { Handler.status(Status.NotImplemented) - } else if (!allowedMethods.contains(req.method) && allowedMethods.nonEmpty) { - Handler.status(Status.MethodNotAllowed) } else { Handler.notFound } case 1 => chunk(0) case n => // TODO: Support precomputed fallback among all chunk elements