Skip to content

Commit

Permalink
Proxy issue
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyzimarev committed Oct 22, 2017
1 parent f2c8fc3 commit b9d05bf
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 16 deletions.
3 changes: 1 addition & 2 deletions RestSharp/Http.Async.cs
Expand Up @@ -385,8 +385,7 @@ private HttpWebRequest ConfigureAsyncWebRequest(string method, Uri url)
if (ReadWriteTimeout != 0)
webRequest.ReadWriteTimeout = ReadWriteTimeout;

if (Proxy != null)
webRequest.Proxy = Proxy;
webRequest.Proxy = Proxy;

if (CachePolicy != null)
webRequest.CachePolicy = CachePolicy;
Expand Down
3 changes: 1 addition & 2 deletions RestSharp/Http.Sync.cs
Expand Up @@ -258,8 +258,7 @@ private HttpWebRequest ConfigureWebRequest(string method, Uri url)
if (Credentials != null)
webRequest.Credentials = Credentials;

if (Proxy != null)
webRequest.Proxy = Proxy;
webRequest.Proxy = Proxy;

if (CachePolicy != null)
webRequest.CachePolicy = CachePolicy;
Expand Down
16 changes: 4 additions & 12 deletions RestSharp/RestClient.cs
Expand Up @@ -477,20 +477,12 @@ private void ConfigureHttp(IRestRequest request, IHttp http)
});
}
}
ConfigureProxy(http);
http.RemoteCertificateValidationCallback = RemoteCertificateValidationCallback;
}

private void ConfigureProxy(IHttp http)
{
if (Proxy != null)
http.Proxy = Proxy;
http.Proxy = Proxy;
#if NETSTANDARD2_0
else
{
http.Proxy = new DefaultProxy();
}
if (http.Proxy == null)
WebRequest.DefaultWebProxy = null;
#endif
http.RemoteCertificateValidationCallback = RemoteCertificateValidationCallback;
}

private static RestResponse ConvertToRestResponse(IRestRequest request, HttpResponse httpResponse)
Expand Down

2 comments on commit b9d05bf

@0x4a616e
Copy link

Choose a reason for hiding this comment

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

The result of this commit seems to be that RestSharp is no longer using the globally configured default proxy when no proxy was explicitly set. Was that intended or is there another way to automatically fall back to the system wide proxy other than explicitly calling restClient.Proxy = WebRequest.DefaultWebProxy; every time a rest client is instantiated?

@alexeyzimarev
Copy link
Member Author

Choose a reason for hiding this comment

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

The issue is that WebRequest.DefaultWebProxy does not work in .NET Core. At least we were getting not supported exception until this commit. If you can test it and submit a PR - I will be more than happy to take it in since we have an open issue #1043, which seems to be related but I am not sure how.

Please sign in to comment.