sttp icon indicating copy to clipboard operation
sttp copied to clipboard

Http proxy problem with async-http-client-backend-zio:3.9.1

Open mev42 opened this issue 1 year ago • 0 comments
trafficstars

I'm trying to get a response using an http proxy with authorization. The application crashes with the following error:

timestamp=2024-01-10T07:00:06.145899Z level=ERROR thread=#zio-fiber-1 message="" cause="Exception in thread "zio-fiber-4" java.lang.NullPointerException: flowPublisher
	at java.base/java.util.Objects.requireNonNull(Objects.java:246)
	at org.reactivestreams.FlowAdapters.toPublisher(FlowAdapters.java:28)
	at sttp.client3.httpclient.zio.HttpClientZioBackend.bodyHandlerBodyToBody(HttpClientZioBackend.scala:55)
	at sttp.client3.httpclient.zio.HttpClientZioBackend.bodyHandlerBodyToBody(HttpClientZioBackend.scala:28)
	at sttp.client3.HttpClientAsyncBackend.$anonfun$sendRegular$3(HttpClientAsyncBackend.scala:57)
	at sttp.client3.HttpClientAsyncBackend.$anonfun$sendRegular$3$adapted(HttpClientAsyncBackend.scala:55)
	at sttp.client3.internal.SttpToJavaConverters$$anon$2.accept(SttpToJavaConverters.scala:12)
	at java.base/java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:859)
	at java.base/java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:837)
	at java.base/java.util.concurrent.CompletableFuture$Completion.run(CompletableFuture.java:478)
	at zio.internal.ZScheduler$$anon$4.run(ZScheduler.scala:478)
	at sttp.client3.impl.zio.RIOMonadAsyncError.error(RIOMonadAsyncError.scala:24)
	at sttp.client3.impl.zio.RIOMonadAsyncError.flatMap(RIOMonadAsyncError.scala:12)
	at sttp.client3.impl.zio.RIOMonadAsyncError.map(RIOMonadAsyncError.scala:9)"

Zio code:

import sttp.client3._
import sttp.client3.httpclient.zio.HttpClientZioBackend
import zio._

object ProxyTest extends ZIOAppDefault {
  override def run: ZIO[Any with ZIOAppArgs with Scope, Any, Any] = {
    HttpClientZioBackend(
      options = SttpBackendOptions.httpProxy(
        "1.2.3.4",
        1234,
        "user",
        "pass"
      )
    ).flatMap { b =>
      quickRequest
        .get(uri"http://2ip.ru")
        .send(b)
    }
  }
}

Using async-http-client-backend-cats everything is ok

import cats.effect
import cats.effect.{ExitCode, IO, IOApp}
import sttp.client3._
import sttp.client3.asynchttpclient.cats.AsyncHttpClientCatsBackend

object ProxyTest extends IOApp {
  override def run(args: List[String]): effect.IO[effect.ExitCode] = {
    AsyncHttpClientCatsBackend[IO](
      options = SttpBackendOptions.httpProxy(
        "1.2.3.4",
        1234,
        "user",
        "pass"
      )
    ).flatMap { b =>
      quickRequest
        .get(uri"http://2ip.ru")
        .send(b)
        .as(ExitCode.Success)
    }
  }
}

mev42 avatar Jan 10 '24 07:01 mev42