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

HttpClientHandler manipulation #18

Open
gratinierer opened this issue Dec 11, 2019 · 0 comments
Open

HttpClientHandler manipulation #18

gratinierer opened this issue Dec 11, 2019 · 0 comments

Comments

@gratinierer
Copy link

In some cases it is necessary to adjust the HttpClientHandler that is used by HttpClient (e.g. using certificates, configure SSL etc.).
After walking through the code for a while I recognized that the HttpClient seems to be replaceable via ConnectionPreferences via

public HttpClient HttpService { get; set; }

Fine at first glance, but

  1. this only sets one instance of an client. So looking at
      var masterService = preferences.HttpService ?? DefaultService.Invoke();
      var arasSerice = preferences.HttpService ?? DefaultService.Invoke();

shows that two separate clients are build, but if you set it via preferences there is only one client. I'm not sure if everything still works with a single instance.
2. There are places where the DefaultService is used, even if you set another client via preferences: public static IPromise<Stream> AsFile(this IReadOnlyProperty prop, IConnection conn, bool async) seems go always via the default client.

So my next idea was to implement a

    public Action<HttpClientHandler> HttpClientHandlerEnricher
    {
      get => _httpClientHandlerEnricher ?? (h => { });
      set => _httpClientHandlerEnricher = HttpClientHandlerEnricher;
    }

This Action could be part of the ConnectionPreferences and then be called on the handlers. In first place this had to happed in the Factory itself, because (1.) and (2.), r.g.

    static Factory()
    {
      DefaultService = () =>
      {
        var handler = new SyncClientHandler
        {
          CookieContainer = new CookieContainer()
        };
        ConnectionPreferences.HttpClientHandlerEnricher(handler);

Unfortunately the static initializer avoids that any ConnectionPreferences are set at that moment.

So I don't have a good idea of placing the handler-manipulating code. But maybe I'm missing something and there is already a solution for that.

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

1 participant