Skip to content

Commit

Permalink
Do not pass Proxy.NoProxy so that the system proxy settings are respe…
Browse files Browse the repository at this point in the history
…cted (#3060)

Do not pass Proxy.NoProxy to respect system proxy. As documented in https://developer.android.com/reference/java/net/URL.html#openConnection(java.net.Proxy)
Passing `Proxy.NoProxy` causes the connection to ignore all proxies, including the system one. This is not the intended outcome of the proxy code here, so make sure
that whenever `GetJavaProxy` returns `Proxy.NoProxy` we do the right thing and call the parameterless overload of `URL.OpenConnection`.
  • Loading branch information
sdebruyn authored and grendello committed May 6, 2019
1 parent 8b23410 commit 4ff4882
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Mono.Android/Xamarin.Android.Net/AndroidClientHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,14 @@ protected virtual IHostnameVerifier GetSSLHostnameVerifier (HttpsURLConnection c
while (true) {
URL java_url = new URL (EncodeUrl (redirectState.NewUrl));
URLConnection java_connection;
if (UseProxy)
java_connection = java_url.OpenConnection (await GetJavaProxy (redirectState.NewUrl, cancellationToken));
else
if (UseProxy) {
var javaProxy = await GetJavaProxy (redirectState.NewUrl, cancellationToken).ConfigureAwait (continueOnCapturedContext: false);
// When you use the parameter Java.Net.Proxy.NoProxy the system proxy is overriden. Leave the parameter out to respect the default settings.
java_connection = javaProxy == Java.Net.Proxy.NoProxy ? java_url.OpenConnection () : java_url.OpenConnection (javaProxy);
} else {
// In this case the consumer of this class has explicitly chosen to not use a proxy, so bypass the default proxy. The default value of UseProxy is true.
java_connection = java_url.OpenConnection (Java.Net.Proxy.NoProxy);
}

var httpsConnection = java_connection as HttpsURLConnection;
if (httpsConnection != null) {
Expand Down

0 comments on commit 4ff4882

Please sign in to comment.