diff --git a/tapir/jvm/src/main/scala/works/iterative/tapir/CustomTapirPlatformSpecific.scala b/tapir/jvm/src/main/scala/works/iterative/tapir/CustomTapirPlatformSpecific.scala index 1785fb1..6af94e2 100644 --- a/tapir/jvm/src/main/scala/works/iterative/tapir/CustomTapirPlatformSpecific.scala +++ b/tapir/jvm/src/main/scala/works/iterative/tapir/CustomTapirPlatformSpecific.scala @@ -48,22 +48,19 @@ case None => identity } - val clientLayer: TaskLayer[Backend] = - ZLayer { - for - sessionId <- zio.System.env("SESSION") - result <- ZIO.succeed(optionallyAddSession(sessionId)) - yield result - }.flatMap(sessionMod => - HttpClientZioBackend.layerUsingClient( - sessionMod.get - .apply( - HttpClient - .newBuilder() - .followRedirects(HttpClient.Redirect.NEVER) - ) - .build() + def clientSessionLayer(sessionId: Option[String]): TaskLayer[Backend] = + HttpClientZioBackend.layerUsingClient( + optionallyAddSession(sessionId)( + HttpClient + .newBuilder() + .followRedirects(HttpClient.Redirect.NEVER) ) + .build() + ) + + val clientLayer: TaskLayer[Backend] = + ZLayer(zio.System.env("SESSION")).flatMap(sessionId => + clientSessionLayer(sessionId.get) ) def makeClient[I, E, O](