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

ModernHttpClient support? #24

Closed
omares opened this issue Jan 13, 2015 · 6 comments
Closed

ModernHttpClient support? #24

omares opened this issue Jan 13, 2015 · 6 comments

Comments

@omares
Copy link

omares commented Jan 13, 2015

Hey, is there a way to use the ModernHttpClient instead of HttpClient?

@tmenier
Copy link
Owner

tmenier commented Jan 13, 2015

Sure. Looks like ModernHttpClient is implemented via a custom HttpMessageHandler, which is simple to wire into all Flurl.Http calls via a custom factory like this:

using Flurl.Http.Configuration;

public class ModernHttpClientFactory : DefaultHttpClientFactory
{
    public override HttpMessageHandler CreateMessageHandler() {
        return new ModernHttpClient.NativeMessageHandler();
    }
}

Then on app startup, register it with Flurl thusly:

FlurlHttp.Configure(c => {
    c.HttpClientFactory = new ModernHttpClientFactory();
});

Let me know if this works for you.

@tmenier
Copy link
Owner

tmenier commented Feb 1, 2015

Closing this issue. If for some reason it did not work, feel free to re-open or just comment.

@tmenier tmenier closed this as completed Feb 1, 2015
@NateRickard
Copy link

Just confirming - this does seem to work and is exactly what I was looking for. I suggest you add this example to your docs under /extensibility.

@tmenier
Copy link
Owner

tmenier commented Apr 22, 2015

Great. Yeah I was just reminded in another issue that CreateMessageHandler needs to be documented.

Nice to see Flurl getting some traction with Xamarin users, would love to figure out how to get the word out more broadly.

@galmok
Copy link

galmok commented Jul 6, 2016

What if we do not want to make a global Flurl configuration, but decide on a per request which httpclient is to be used?

In our case we want to selectively ignore certificate validation.

@tmenier
Copy link
Owner

tmenier commented Jul 10, 2016

@galmok No problem - the same global settings object is available per FlurlClient instance via the Settings property.

var client = new FlurlClient();
client.Settings.HttpClientFactory = new MyCustomFactory();
var result = await "http://api.com".WithClient(client).GetAsync();

The docs need to be updated in this area.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants