Prevent OkHttp/Retrofit from bypassing proxy
<p>When OkHttp tries a proxy, and that route fails once, every request after that request will completely bypass the Android system proxy. So it is difficult to debug using Charles.</p>

<p>I currently have the code below, but it is setup to only be for Debug builds. It works great, but it's a hack, and we're looking to release this for all users.</p>

<p>Is there some hidden OkHttpClient.dontBypassProxy setting that I can't find? Or, does the code below look like a good solution?</p>

<pre><code>    OkHttpClient.Builder baseClientBuilder = new OkHttpClient.Builder().retryOnConnectionFailure(false).connectionPool(new ConnectionPool(5, 20, TimeUnit.SECONDS));

    //Ask OkHttp what proxies we have setup
    List&lt;Proxy&gt; proxies = ProxySelector.getDefault().select(URI.create("http://www.somesite.com"));

    if (proxies.size() &gt; 0 &amp;&amp; proxies.get(0) != Proxy.NO_PROXY) {
        //Force OkHttp to always use this proxy
        baseClientBuilder.proxy(proxies.get(0));
    }
</code></pre>