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

Improve extensibility of DefaultHttpMessageInvokerFactory #141

Merged
merged 1 commit into from
Oct 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions src/Duende.Bff.Yarp/DefaultHttpMessageInvokerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ namespace Duende.Bff.Yarp;

/// <summary>
/// Default implementation of the message invoker factory.
/// This implementation creates one message invoke per remote API endpoint
/// This implementation creates one message invoker per remote API endpoint.
/// </summary>
public class DefaultHttpMessageInvokerFactory : IHttpMessageInvokerFactory
{
/// <summary>
/// Dictionary to cachen invoker instances
/// Dictionary to cache invoker instances
/// </summary>
protected readonly ConcurrentDictionary<string, HttpMessageInvoker> Clients = new();

Expand All @@ -23,15 +23,19 @@ public virtual HttpMessageInvoker CreateClient(string localPath)
{
return Clients.GetOrAdd(localPath, (key) =>
{
var socketsHandler = new SocketsHttpHandler
{
UseProxy = false,
AllowAutoRedirect = false,
AutomaticDecompression = DecompressionMethods.None,
UseCookies = false
};

return new HttpMessageInvoker(socketsHandler);
var handler = CreateHandler(key);
return new HttpMessageInvoker(handler);
});
}
}

protected virtual HttpMessageHandler CreateHandler(string localPath)
{
return new SocketsHttpHandler
{
UseProxy = false,
AllowAutoRedirect = false,
AutomaticDecompression = DecompressionMethods.None,
UseCookies = false
};
}
}