Skip to content

Commit

Permalink
Merge branch 'main' into clean/AtomizedCodecs
Browse files Browse the repository at this point in the history
  • Loading branch information
guizmaii authored Dec 5, 2024
2 parents 8905d4b + 1f8ef1f commit e034763
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
10 changes: 10 additions & 0 deletions zio-http/jvm/src/test/scala/zio/http/ClientSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,16 @@ object ClientSpec extends RoutesRunnableSpec {
app.deploy(Request(headers = Headers(Header.Authorization.Unparsed("", "my-token")))).flatMap(_.body.asString)
assertZIO(responseContent)(equalTo("my-token"))
} @@ timeout(5.seconds),
test("URL and path manipulation on client level") {
for {
baseURL <- DynamicServer.httpURL
_ <-
Handler.ok.toRoutes.deployAndRequest { c =>
(c.updatePath(_ / "my-service") @@ ZClientAspect.requestLogging()).batched.get("/hello")
}.runZIO(())
loggedUrl <- ZTestLogger.logOutput.map(_.collectFirst { case m => m.annotations("url") }.mkString)
} yield assertTrue(loggedUrl == baseURL + "/my-service/hello")
},
)

override def spec = {
Expand Down
8 changes: 6 additions & 2 deletions zio-http/shared/src/main/scala/zio/http/ZClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,10 @@ final case class ZClient[-Env, ReqEnv, -In, +Err, +Out](

def path(path: String): ZClient[Env, ReqEnv, In, Err, Out] = self.path(Path(path))

def path(path: Path): ZClient[Env, ReqEnv, In, Err, Out] =
copy(url = url.copy(path = path))
def path(path: Path): ZClient[Env, ReqEnv, In, Err, Out] = updatePath(_ => path)

def updatePath(f: Path => Path): ZClient[Env, ReqEnv, In, Err, Out] =
copy(url = url.copy(path = f(url.path)))

def patch(suffix: String)(implicit ev: Body <:< In, trace: Trace): ZIO[Env & ReqEnv, Err, Out] =
request(Method.PATCH, suffix)(ev(Body.empty))
Expand Down Expand Up @@ -263,6 +265,8 @@ final case class ZClient[-Env, ReqEnv, -In, +Err, +Out](
def uri(uri: URI): ZClient[Env, ReqEnv, In, Err, Out] = url(URL.fromURI(uri).getOrElse(URL.empty))

def url(url: URL): ZClient[Env, ReqEnv, In, Err, Out] = copy(url = url)

def updateURL(f: URL => URL): ZClient[Env, ReqEnv, In, Err, Out] = copy(url = f(url))
}

object ZClient extends ZClientPlatformSpecific {
Expand Down

2 comments on commit e034763

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 : Performance Benchmarks (SimpleEffectBenchmarkServer)

concurrency: 256
requests/sec: 355955

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 : Performance Benchmarks (PlainTextBenchmarkServer)

concurrency: 256
requests/sec: 352759

Please sign in to comment.