Skip to content

Commit

Permalink
Minor interface update for IPrimaryHandlerFactory, csproj update
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Gertenbach committed Mar 3, 2024
1 parent b02861a commit 7793a18
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 16 deletions.
7 changes: 0 additions & 7 deletions Ringleader.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RingleaderTests", "Ringlead
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebExample", "WebExample\WebExample.csproj", "{219EDA92-D634-40C0-A71A-7B49275FF086}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E7CBD922-598B-4B9A-B72D-3D3C28A9B136}"
ProjectSection(SolutionItems) = preProject
.gitignore = .gitignore
.github\workflows\dotnetcore.yml = .github\workflows\dotnetcore.yml
README.md = README.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public Action<HttpMessageHandlerBuilder> Configure(Action<HttpMessageHandlerBuil
string client = _resolver.ParseClientName(builder.Name);
string handlerContext = _resolver.ParseHandlerName(builder.Name);
_logger.LogDebug("Building primary handler for client [{client}] with context [{context}]", client, handlerContext);
builder.PrimaryHandler = _primaryHandlerFactory.CreateHandler(client, handlerContext);
builder.PrimaryHandler = _primaryHandlerFactory.CreateHandler(client, handlerContext) ?? builder.PrimaryHandler;
if (builder.PrimaryHandler is HttpClientHandler h) h.Properties.TryAdd("Handler Context", handlerContext);
else if (builder.PrimaryHandler is SocketsHttpHandler s) s.Properties.TryAdd("Handler Context", handlerContext);
next(builder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class DefaultActionedPrimaryHandlerFactoryOptions
/// Function to optionally resolve an <see cref="HttpMessageHandler"/> based on a specified client and/or context
/// </summary>
public Func<string, string, HttpMessageHandler?> HandlerFactory { get; set; }
= (client, context) => new HttpClientHandler();
= (client, context) => null;
}

/// <summary>
Expand All @@ -27,7 +27,7 @@ public DefaultActionedPrimaryHandlerFactory(IOptionsMonitor<DefaultActionedPrima
_options = options ?? throw new ArgumentNullException(nameof(options));
}

public HttpMessageHandler CreateHandler(string clientName, string handlerContext)
=> _options.CurrentValue.HandlerFactory.Invoke(clientName, handlerContext) ?? new HttpClientHandler();
public HttpMessageHandler? CreateHandler(string clientName, string handlerContext)
=> _options.CurrentValue.HandlerFactory.Invoke(clientName, handlerContext);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ namespace Ringleader.HttpClientFactory
public interface IPrimaryHandlerFactory
{
/// <summary>
/// Generate a primary <see cref="HttpMessageHandler"/> based on a supplied <see cref="HttpClient"/> name and handler context
/// Optionally create a custom primary <see cref="HttpMessageHandler"/> based on a supplied <see cref="HttpClient"/> name and handler context
/// </summary>
/// <param name="clientName"><see cref="HttpClient"/> name</param>
/// <param name="handlerContext">Handler context for the <see cref="HttpClient"/></param>
/// <returns>An <see cref="HttpMessageHandler"/> configured based on the context</returns>
HttpMessageHandler CreateHandler(string clientName, string handlerContext);
/// <returns>An <see cref="HttpMessageHandler"/> configured based on the context, or <see langword="null"/> to use the default handler</returns>
HttpMessageHandler? CreateHandler(string clientName, string handlerContext);
}
}
5 changes: 3 additions & 2 deletions Ringleader/Ringleader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Authors>Adam Gertenbach</Authors>
<Description>Extends the NET Core default HttpClientFactory to support managing and applying contextually appropriate primary handlers (i.e. unique certificates for different endpoints) while retaining the benefits of handler pooling and typed client pipelines.</Description>
<Description>Extends the .NET DefaultHttpClientFactory to support contextually appropriate primary handlers (i.e. unique certificates for different endpoints) and per-request cookie scope while retaining the benefits of handler pooling and typed client pipelines.</Description>
<Copyright>2020-2024 Adam Gertenbach</Copyright>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>2.0.0</Version>
<Version>2.0.1</Version>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageProjectUrl>https://github.com/agertenbach/Ringleader</PackageProjectUrl>
<RepositoryUrl>https://github.com/agertenbach/Ringleader</RepositoryUrl>
<Nullable>enable</Nullable>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageTags>HttpClientFactory;IHttpClientFactory;HttpClient;DefaultHttpClientFactory;Cookies;Certificates;MessageHandler;PrimaryHandler;</PackageTags>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 7793a18

Please sign in to comment.