Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a proxy server if specified #2385

Merged
merged 1 commit into from
Nov 8, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions src/Mono.Android/Xamarin.Android.Net/AndroidClientHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ protected virtual IHostnameVerifier GetSSLHostnameVerifier (HttpsURLConnection c
URL java_url = new URL (EncodeUrl (redirectState.NewUrl));
URLConnection java_connection;
if (UseProxy)
java_connection = java_url.OpenConnection ();
java_connection = java_url.OpenConnection (await GetJavaProxy (redirectState.NewUrl, cancellationToken));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this constitute a "redirect"? Do we need to worry about Authentication headers here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't constitute a redirect per se, look at the code a few lines above:

var redirectState = new RequestRedirectionState {
    NewUrl = request.RequestUri,
    RedirectCounter = 0,
    Method = request.Method
};
while (true) {
    URL java_url = new URL (EncodeUrl (redirectState.NewUrl));

if there is a redirect, the URL used here will reflect it, otherwise it's the request URL.

Regarding the authentication headers, we do need to worry about them but they have a separate PR (which timed out and is rebuilding now).

else
java_connection = java_url.OpenConnection (Java.Net.Proxy.NoProxy);

Expand All @@ -287,7 +287,30 @@ protected virtual IHostnameVerifier GetSSLHostnameVerifier (HttpsURLConnection c
request.Method = redirectState.Method;
}
}


protected virtual async Task <Java.Net.Proxy> GetJavaProxy (Uri destination, CancellationToken cancellationToken)
{
Java.Net.Proxy proxy = Java.Net.Proxy.NoProxy;

if (destination == null || Proxy == null) {
goto done;
}

Uri puri = Proxy.GetProxy (destination);
if (puri == null) {
goto done;
}

proxy = await Task <Java.Net.Proxy>.Run (() => {
// Let the Java code resolve the address, if necessary
var addr = new Java.Net.InetSocketAddress (puri.Host, puri.Port);
return new Java.Net.Proxy (Java.Net.Proxy.Type.Http, addr);
}, cancellationToken);

done:
return proxy;
}

Task <HttpResponseMessage> ProcessRequest (HttpRequestMessage request, URL javaUrl, HttpURLConnection httpConnection, CancellationToken cancellationToken, RequestRedirectionState redirectState)
{
cancellationToken.ThrowIfCancellationRequested ();
Expand Down