sttp icon indicating copy to clipboard operation
sttp copied to clipboard

async-http-client cannot detect proxy settings

Open user753 opened this issue 5 years ago • 11 comments

HttpURLConnectionBackend works fine without any configuration. But when I try to use async-http-client I get HTTP/1.1 407 Proxy Authentication Required So I need to set

options = SttpBackendOptions.httpProxy()

manually Could async-http-client work the same way as HttpURLConnectionBackend?

user753 avatar Jan 22 '20 12:01 user753

What's your setup? Do you need to connect through a proxy? Maybe you have some JVM-level options (passed when you start java ...) that are picked by the the HttpURLConnectionBackend?

adamw avatar Jan 22 '20 13:01 adamw

@adamw I use windows 10, sbt 1.3.4, scala 2.13.1 Yes, I need to connect through proxy. I have all Dhttp.proxy* settings in sbtconfig.txt and I guess HttpURLConnectionBackend can use them. Can AsyncHttpClientCatsBackend to the same?

user753 avatar Jan 23 '20 07:01 user753

Which async-http-client implementation are you using exactly and how are you creating it?

All backends by default use options: SttpBackendOptions = SttpBackendOptions.Default, which, in turn, load the default proxy:

val Default: SttpBackendOptions = Empty.copy(proxy = loadSystemProxy)

loadSystemProxy looks up the proxy settings using System.getProperty (see SttpBackendOptions.loadSystemProxy). So this should work, unless you are constructing the backend in a way which doesn't pick the default options.

adamw avatar Jan 23 '20 07:01 adamw

SttpBackendOptions.Default has a proxy settings. I use backend like this

val response  = AsyncHttpClientCatsBackend[cats.effect.IO]().flatMap(implicit backend => {
  request.send()
}).unsafeRunSync()

user753 avatar Jan 23 '20 08:01 user753

Hm, looking at the code, the default proxy options should be used. Maybe you can try to debug and see if everything's set up correctly in AsyncHttpClientBackend.defaultConfigBuilder?

Something somewhere is probably wrong but I don't have a way to reproduce this :)

adamw avatar Jan 23 '20 09:01 adamw

So, SttpBackendOptions.Default has system proxy settings with host and port without username and password. HttpURLConnectionBackend can work with such settings

        implicit val backend = HttpURLConnectionBackend(
          options = SttpBackendOptions.httpProxy(proxyhost, proxyport)
        )

but somehow AsyncHttpClientCatsBackend cannot and I also need to add username and password

user753 avatar Jan 23 '20 10:01 user753

Well as I said I don't have a way to debug this, I think the only way is checking if AsyncHttpClientBackend.defaultConfigBuilder is called and if the proxy is properly configured.

adamw avatar Jan 23 '20 13:01 adamw

@adamw I think I found the problem. System.getProperties() has proxyUser and proxyPassword but loadSystemProxy doesn't use them to create ProxyAuth in Proxy

user753 avatar Jan 23 '20 13:01 user753

ah :) can you maybe try creating a PR which would fix that?

adamw avatar Jan 23 '20 15:01 adamw

I will try when I have a free time.

user753 avatar Jan 24 '20 07:01 user753

any update on this one?

halfhp avatar Jul 22 '22 00:07 halfhp