Skip to content

Custom Delegating Handlers to support plug-ins #1935

Answered by MihaZupan
dimevit asked this question in General
Discussion options

You must be logged in to vote

If you're using direct forwarding, you control the HttpClientHandler instance yourself, so you can customize it however you wish.

If you're using the full YARP middleware (.MapReverseProxy()), you can inject custom delegating handlers by implementing a custom IForwarderHttpClientFactory and registering it in DI. See https://microsoft.github.io/reverse-proxy/articles/http-client-config.html

E.g.

services.AddSingleton<IForwarderHttpClientFactory, CustomHttpClientFactory>();

private sealed class CustomHttpClientFactory : ForwarderHttpClientFactory
{
    protected override WrapHandler(ForwarderHttpClientContext context, HttpMessageHandler handler)
    {
        return new MyHandler(handler);

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by dimevit
Comment options

You must be logged in to vote
4 replies
@ChristinaBauer
Comment options

@Tratcher
Comment options

@ChristinaBauer
Comment options

@samsp-msft
Comment options

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