From f2ccf4aaf43cb2e61b152475bd26a05e62302014 Mon Sep 17 00:00:00 2001 From: Saturn225 <101260782+Saturn225@users.noreply.github.com> Date: Sat, 19 Oct 2024 22:07:15 +0530 Subject: [PATCH] Handle OPTIONS Method --- zio-http/shared/src/main/scala/zio/http/Routes.scala | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 8695ebd2ea..2179bf9d8b 100644 --- a/zio-http/shared/src/main/scala/zio/http/Routes.scala +++ b/zio-http/shared/src/main/scala/zio/http/Routes.scala @@ -248,14 +248,18 @@ final case class Routes[-Env, +Err](routes: Chunk[zio.http.Route[Env, Err]]) { s val tree = self.tree Handler .fromFunctionHandler[Request] { req => + println(s"[DEBUG] Incoming request: Method = ${req.method}, Path = ${req.path}") + val chunk = tree.get(req.method, req.path) def allowedMethods = tree.getAllMethods(req.path) + println(s"[DEBUG] Chunk length for Method ${req.method} and Path ${req.path} = ${chunk.length}") + println(s"[DEBUG] Allowed methods for Path ${req.path} = ${allowedMethods.mkString(", ")}") req.method match { case Method.CUSTOM(_) => Handler.notImplemented case _ => if (chunk.isEmpty) { - if (allowedMethods.isEmpty) { + if (allowedMethods.isEmpty || allowedMethods == Set(Method.OPTIONS)) { // If no methods are allowed for the path, return 404 Not Found Handler.notFound } else { @@ -281,6 +285,7 @@ final case class Routes[-Env, +Err](routes: Chunk[zio.http.Route[Env, Err]]) { s } } } + } .merge }