Skip to content

Commit

Permalink
Fix Route merge order to fix Issue zio#3066
Browse files Browse the repository at this point in the history
In case of duplicate routes, the old logic gives precedence to older routes, which breaks cases where the routes are updated with new environments and re-added.

This gives precedence to the newer ones.

/claim zio#3066
  • Loading branch information
exi committed Sep 23, 2024
1 parent 20d27fb commit 52e21c3
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions zio-http/shared/src/main/scala/zio/http/Routes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -251,19 +251,13 @@ final case class Routes[-Env, +Err](routes: Chunk[zio.http.Route[Env, Err]]) { s
val chunk = tree.get(req.method, req.path)
chunk.length match {
case 0 => Handler.notFound
case 1 => chunk(0)
case n => // TODO: Support precomputed fallback among all chunk elements
var acc = chunk(0)
var i = 1
while (i < n) {
val h = chunk(i)
acc = acc.catchAll { response =>
case _ => // TODO: Support precomputed fallback among all chunk elements
chunk.reverseIterator.reduceLeft { (acc, h) =>
acc.catchAll { response =>
if (response.status == Status.NotFound) h
else Handler.fail(response)
}
i += 1
}
acc
}
}
.merge
Expand Down

0 comments on commit 52e21c3

Please sign in to comment.