restsharp.portable icon indicating copy to clipboard operation
restsharp.portable copied to clipboard

ModernHttpClientFactory integration with version 4.0+

Open tele-bird opened this issue 8 years ago • 3 comments

In order to squeeze the best performance from our Xamarin Android/iOS app, we override DefaultHttpClientFactory.CreateMessageHandler(), as described in issue #34. It works great for us!

However, with our upgrade to version 4.0.8 of FubarCoder.RestSharp.Portable.HttpClient, the DefaultHttpClientFactory.CreateMessageHandler() method no longer exists with both parameters --the IRestRequest has been removed. I also notice that GetProxy(), GetCookies() methods and RequestProxyWrapper class no longer exist. So, there have been some fairly substantial changes to this library...

Can anyone provide guidance around how to modify the integration suggested in #34 to comply with the new interfaces available in version 4.0.8 ?

tele-bird avatar Dec 19 '17 18:12 tele-bird

Here's what I have, but it neglects the proxy and cookies, which are now unavailable from the IRestClient and IRestRequest under the latest interface definition. How to support these?

protected override HttpMessageHandler CreateMessageHandler(IRestClient client)
{
    var cookies = client.CookieContainer;
    var credentials = client.Credentials;
    var httpClientHandler = _nativeMessageHandler.GetINativeMessageHandler();
    if (cookies != null)
    {
        httpClientHandler.UseCookies = true;
        httpClientHandler.CookieContainer = cookies;
    }
    if (credentials != null)
    {
        httpClientHandler.Credentials = credentials;
    }
    return httpClientHandler;
}

tele-bird avatar Dec 19 '17 20:12 tele-bird

The main problem with IWebProxy was, that it wasn't available for some target frameworks. I'll convert the project.json stuff to the new csproj format, remove the PCL stuff and add more platforms supporting IWebProxy. This will be released as version 5.0. Is this sufficient for you?

fubar-coder avatar Dec 19 '17 22:12 fubar-coder

if these DefaultHttpClientFactory methods will be present in version 5.0 (as they were in version 3.x), then yes:

var proxy = GetProxy(client);
var cookies = GetCookies(client, request);

Thank you!

tele-bird avatar Dec 20 '17 13:12 tele-bird