Soenneker.Dtos.HttpClientOptions 4.0.32

Prefix Reserved
dotnet add package Soenneker.Dtos.HttpClientOptions --version 4.0.32
                    
NuGet\Install-Package Soenneker.Dtos.HttpClientOptions -Version 4.0.32
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Soenneker.Dtos.HttpClientOptions" Version="4.0.32" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Dtos.HttpClientOptions" Version="4.0.32" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Dtos.HttpClientOptions" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Soenneker.Dtos.HttpClientOptions --version 4.0.32
                    
#r "nuget: Soenneker.Dtos.HttpClientOptions, 4.0.32"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Soenneker.Dtos.HttpClientOptions@4.0.32
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Soenneker.Dtos.HttpClientOptions&version=4.0.32
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Dtos.HttpClientOptions&version=4.0.32
                    
Install as a Cake Tool

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

Soenneker.Dtos.HttpClientOptions

Describes client, transport, and handler-pipeline settings for Soenneker.Utils.HttpClientCache.

Installation

dotnet add package Soenneker.Dtos.HttpClientOptions

Common configuration

using System.Net;
using Soenneker.Dtos.HttpClientOptions;

var options = new HttpClientOptions
{
    BaseAddress = new Uri("https://api.example.com/"),
    Timeout = TimeSpan.FromSeconds(30),
    ConnectTimeout = TimeSpan.FromSeconds(5),
    PooledConnectionLifetime = TimeSpan.FromMinutes(10),
    MaxConnectionsPerServer = 40,
    AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate,
    DefaultRequestHeaders = new Dictionary<string, string>
    {
        ["Accept"] = "application/json"
    }
};

Timeout applies to the overall HttpClient request. ConnectTimeout applies only while establishing a connection. When consumed by HttpClientCache, null values use a 100-second request timeout, a 100-second connect timeout, a 10-minute pooled-connection lifetime, and 40 connections per server.

Cookies, redirects, and proxies

var options = new HttpClientOptions
{
    UseCookieContainer = true,
    AllowAutoRedirect = false,
    UseProxy = true,
    Proxy = new WebProxy("http://proxy.example.com:8080")
};

Cookies are disabled unless UseCookieContainer is true. Enabling them gives the cached client a dedicated cookie container rather than a shared transport. Supplying Proxy, SslOptions, or ModifyPrimaryHandler also creates a dedicated transport.

Automatic redirects default to the handler behavior (enabled). Disable them when non-Authorization default headers contain secrets and redirected hosts are not fully trusted.

Customize client and handlers

var options = new HttpClientOptions
{
    ModifyClient = client =>
    {
        client.DefaultRequestHeaders.UserAgent.ParseAdd("ExampleClient/1.0");
        return ValueTask.CompletedTask;
    },
    ModifyPrimaryHandler = handler =>
    {
        handler.EnableMultipleHttp2Connections = true;
    },
    DelegatingHandlerFactories =
    [
        static () => new CorrelationHandler(),
        static () => new MetricsHandler()
    ]
};

Callbacks and factories run once when the cached client is created. Each delegating-handler factory must return a new handler whose InnerHandler is unset. The first factory becomes the outermost handler. The cache owns and disposes the resulting pipeline.

Remaining transport limits

  • ResponseDrainTimeout and MaxResponseDrainSize control draining content when responses are disposed before their bodies are consumed. Drain size is measured in bytes.
  • MaxResponseHeadersLength is measured in kilobytes; the framework default is 64 KB.
  • KeepAlivePingDelay, KeepAlivePingTimeout, and KeepAlivePingPolicy configure HTTP/2 or HTTP/3 keep-alive pings.
  • SslOptions replaces TLS client-authentication settings for a dedicated handler. Avoid certificate-validation callbacks that accept untrusted certificates.

This is a runtime options object, not a portable serialization contract: it contains delegates, handlers, proxy objects, and TLS settings. Construct it in code. The cache reads it only during first initialization for a key, so later calls with different options—or mutations after creation—should not be used to reconfigure an existing client.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Soenneker.Dtos.HttpClientOptions:

Package Downloads
Soenneker.Utils.HttpClientCache

Providing thread-safe singleton HttpClients

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.0.32 183 9/12/2026
4.0.31 175,494 8/30/2026
4.0.30 132 8/29/2026
4.0.29 134,873 8/13/2026
4.0.28 97 8/13/2026
4.0.27 103,387 7/27/2026
4.0.26 111,029 7/16/2026
4.0.25 122,146 6/18/2026
4.0.24 114,938 6/5/2026
4.0.23 169,023 4/22/2026
4.0.22 130,972 3/12/2026
4.0.21 136 3/12/2026
4.0.20 126 3/12/2026
4.0.19 5,247 3/12/2026
4.0.18 24,741 3/10/2026
4.0.17 18,967 3/9/2026
4.0.16 128 3/9/2026
4.0.15 3,734 3/9/2026
4.0.14 35,264 3/4/2026
4.0.13 212,544 1/5/2026
Loading failed

Use NuGet trusted publishing in publishing workflows