okhttp

Does OkHttp honor the proxy and non-proxy system settings?


We are in a case where a microservice needs to use a proxy for some calls, but not all. Additionally, OkHttp is used by one of the libraries we rely on, so we do not want to add extra code, we want to use only configuration updates. So we planned on using the usual system properties -Dhttps.proxyHost, -Dhttps.proxyPort, and -Dhttps.nonProxyHosts as JVM arguments. I see a lot of discussions regarding the actual support of proxies in OkHpttp, so the question is basically: Does OkHttp honor those system settings? My testing seems to go in the direction of nonProxyHosts non being honored, but I prefer to be sure as I get:

java.net.ProtocolException: unexpected end of stream
at okhttp3.internal.http1.Http1ExchangeCodec$FixedLengthSource.read(Http1ExchangeCodec.kt:371)

Thanks


Solution

  • After further digging I can confirm it works, but there was a catch (at least for my case): i was using IP ranges for the non-proxy variables which was not working. I switched to hosts, e.g. *.svc.cluster.local and that fixed my issue.