diff --git a/zio-http/jvm/src/test/scala/zio/http/endpoint/NotFoundSpec.scala b/zio-http/jvm/src/test/scala/zio/http/endpoint/NotFoundSpec.scala index 08510153ea..b09ba78fb3 100644 --- a/zio-http/jvm/src/test/scala/zio/http/endpoint/NotFoundSpec.scala +++ b/zio-http/jvm/src/test/scala/zio/http/endpoint/NotFoundSpec.scala @@ -87,7 +87,7 @@ object NotFoundSpec extends ZIOHttpSpec { result = response.status == Status.NotFound } yield assertTrue(result) } - + def test405[R](service: Routes[R, Nothing])( url: String, method: Method, 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 a36ecf95c1..cb51ace73e 100644 --- a/zio-http/shared/src/main/scala/zio/http/Routes.scala +++ b/zio-http/shared/src/main/scala/zio/http/Routes.scala @@ -252,14 +252,14 @@ final case class Routes[-Env, +Err](routes: Chunk[zio.http.Route[Env, Err]]) { s chunk.length match { case 0 => val allowedMethods = Method.all.filter(method => tree.get(method, req.path).nonEmpty) - if (allowedMethods.nonEmpty) { + if (allowedMethods.isEmpty) { + Handler.notFound + } else { Handler.succeed( Response .status(Status.MethodNotAllowed) .addHeader(Header.Allow(NonEmptyChunk.fromIterable(allowedMethods.head, allowedMethods.tail))), ) - } else { - Handler.notFound } case 1 => chunk(0) case n => // TODO: Support precomputed fallback among all chunk elements