Git Product home page Git Product logo

Comments (9)

Timovzl avatar Timovzl commented on June 21, 2024 2

@davidfowl To clarify, I see the HttpClientHandler being created at configuration time. At this point in the application (startup), we do not have the necessary information.

Each time we want to use the HttpClient, we load a certificate (perhaps based on a fingerprint), with the intention of getting an HttpClientHandler that uses that particular certificate. How can we achieve this?

from httpclientfactory.

rynowak avatar rynowak commented on June 21, 2024 1

Great! glad we could help

from httpclientfactory.

martincostello avatar martincostello commented on June 21, 2024

Looks like you call ConfigurePrimaryHttpMessageHandler() as part of using the HttpClient builders:

public static IHttpClientBuilder ConfigurePrimaryHttpMessageHandler(this IHttpClientBuilder builder, Func<HttpMessageHandler> configureHandler)

from httpclientfactory.

rynowak avatar rynowak commented on June 21, 2024

Yes, @martincostello is right. You can configure the primary handler used by the factory for each named client this way.

from httpclientfactory.

evertmulder avatar evertmulder commented on June 21, 2024

@martincostello @rynowak Thanks a lot for pointing me in the right direction. I will test this tomorrow, but the following should do the trick.

services.AddHttpClient("named", c =>
{
    c.BaseAddress = new Uri("TODO");
    c.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
    c.DefaultRequestHeaders.CacheControl = new CacheControlHeaderValue
    {
        NoCache = true,
        NoStore = true,
        MaxAge = new TimeSpan(0),
        MustRevalidate = true
    };
}).ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler
{
    AllowAutoRedirect = false,
    AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip
});

from httpclientfactory.

Timovzl avatar Timovzl commented on June 21, 2024

What if the handler must specify client certificates that are determined at runtime?

from httpclientfactory.

davidfowl avatar davidfowl commented on June 21, 2024

What’s the complication there?

from httpclientfactory.

fleed avatar fleed commented on June 21, 2024

@Timovzl I'm facing the same problem. I was expecting an overload of the AddHttpClient method providing the IServiceProvider instance, as it is in other circumstances.
Did you find an alternative solution?

from httpclientfactory.

rynowak avatar rynowak commented on June 21, 2024

Please open a new issue rather than commenting on a closed issue.

from httpclientfactory.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.