sttp
sttp copied to clipboard
async-http-client cannot detect proxy settings
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?
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 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?
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.
SttpBackendOptions.Default has a proxy settings.
I use backend like this
val response = AsyncHttpClientCatsBackend[cats.effect.IO]().flatMap(implicit backend => {
request.send()
}).unsafeRunSync()
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 :)
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
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 I think I found the problem. System.getProperties() has proxyUser and proxyPassword but loadSystemProxy doesn't use them to create ProxyAuth in Proxy
ah :) can you maybe try creating a PR which would fix that?
I will try when I have a free time.
any update on this one?