Skip to content

Commit

Permalink
Use URI to retrieve decoded path segments in ArmeriaServerRequest (#4163
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Uko authored Nov 13, 2024
1 parent f964d03 commit 0a0d9f2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,8 @@ private[armeria] final case class ArmeriaServerRequest(ctx: ServiceRequestContex
override def underlying: Any = ctx

override val pathSegments: List[String] = {
// ctx.path() always starts with '/'.
if (ctx.path() == "/") {
Nil
} else {
ctx.path().substring(1).split("/").toList
}
val segments = uri.pathSegments.segments.map(_.v).filter(_.nonEmpty).toList
if (segments == List("")) Nil else segments // representing the root path as an empty list
}

override val queryParameters: QueryParams = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,12 @@ class ServerBasicTests[F[_], OPTIONS, ROUTE](
(backend, baseUri) =>
basicRequest.get(uri"$baseUri/api").send(backend).map(_.code shouldBe StatusCode.Ok)
},
testServer(in_path_paths_out_header_body, "Encoded path should be decoded") { case (i, paths) =>
pureResult(Right((i, paths.last)))
}{
(backend, baseUri) =>
basicRequest.get(uri"$baseUri/api/15/and/MIN%2FMAX").send(backend).map(_.body shouldBe Right("MIN/MAX"))
},
testServer(in_single_path, "single path should match single/ path")((_: Unit) => pureResult(Either.right[Unit, Unit](()))) {
(backend, baseUri) =>
basicRequest.get(uri"$baseUri/api/").send(backend).map(_.code shouldBe StatusCode.Ok)
Expand Down

0 comments on commit 0a0d9f2

Please sign in to comment.