Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about RequestInterceptor #1207

Closed
darl opened this issue Dec 14, 2021 · 1 comment · Fixed by #1208
Closed

Question about RequestInterceptor #1207

darl opened this issue Dec 14, 2021 · 1 comment · Fixed by #1208
Labels
adapters Issue related to HTTP adapters server Issue related to caliban server

Comments

@darl
Copy link
Contributor

darl commented Dec 14, 2021

I'm trying to upgrade caliban to 1.3.0.
Found that ContextWrapper disappeared and RequestInterceptor takes its place.

My use case is to extract context from request and provide it as ZIO environment:

def contextExtractor(log: Logging.Service): ContextWrapper[World, HttpResponse] =
    new ContextWrapper[World, HttpResponse] {

      override def apply[R1 <: World, A1 >: HttpResponse](ctx: RequestContext)(effect: URIO[R1, A1]): URIO[R1, A1] = {
        for {
          world <- ZIO.service[World.Service]
          ctx = AkkaRequestContextReader.readFrom(ctx.request)
          braveNewWorld <- world.withContext(ctx)
          res <- effect.provideSomeLayer[R1](ZLayer.succeed(braveNewWorld))
        } yield res
      }
    }

RequestInterceptor doesn't have access to effect so the only solution I see is to pass information via FiberRef. Downside

Can we make RequestInterceptor behave like the old ContextWrapper?

@ghostdogpr
Copy link
Owner

Good point! I restored that capability in #1208

@ghostdogpr ghostdogpr added adapters Issue related to HTTP adapters server Issue related to caliban server labels Dec 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
adapters Issue related to HTTP adapters server Issue related to caliban server
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants