Soenneker.Extensions.HttpContent
4.0.947
Prefix Reserved
dotnet add package Soenneker.Extensions.HttpContent --version 4.0.947
NuGet\Install-Package Soenneker.Extensions.HttpContent -Version 4.0.947
<PackageReference Include="Soenneker.Extensions.HttpContent" Version="4.0.947" />
<PackageVersion Include="Soenneker.Extensions.HttpContent" Version="4.0.947" />
<PackageReference Include="Soenneker.Extensions.HttpContent" />
paket add Soenneker.Extensions.HttpContent --version 4.0.947
#r "nuget: Soenneker.Extensions.HttpContent, 4.0.947"
#:package Soenneker.Extensions.HttpContent@4.0.947
#addin nuget:?package=Soenneker.Extensions.HttpContent&version=4.0.947
#tool nuget:?package=Soenneker.Extensions.HttpContent&version=4.0.947
Soenneker.Extensions.HttpContent
Extensions for cloning, inspecting, and logging HttpContent without forcing every caller to choose its own buffering strategy.
Installation
dotnet add package Soenneker.Extensions.HttpContent
Clone content for another request
using Soenneker.Extensions.HttpContent;
using HttpContent? copy = await originalContent.Clone(cancellationToken: cancellationToken);
if (copy is not null)
{
using var request = new HttpRequestMessage(HttpMethod.Post, destination)
{
Content = copy
};
await httpClient.SendAsync(request, cancellationToken);
}
Clone() copies the body and content headers into independently disposable content. It returns null for a null input. Cloning reads the original body, so do not assume a non-seekable original stream can be read again afterward.
An IMemoryStreamUtil can be supplied when the application already uses pooled memory streams:
using HttpContent? copy = await originalContent.Clone(memoryStreamUtil, cancellationToken);
Choose buffering or streaming
ShouldUseStream() returns true when Content-Length is unknown or greater than 64 KiB. GetSmallContentBytes() reads a body only when its declared length is at most 64 KiB:
if (content.ShouldUseStream())
{
await using Stream stream = await content.ReadAsStreamAsync(cancellationToken);
await ProcessStream(stream, cancellationToken);
}
else
{
ReadOnlyMemory<byte> bytes = await content.GetSmallContentBytes(cancellationToken);
ProcessBytes(bytes.Span);
}
GetSmallContentBytes() returns empty memory for null, zero-length, unknown-length, and oversized content. Use ShouldUseStream() when the distinction matters. These decisions trust the declared Content-Length; they are a routing aid, not an enforcement limit.
Add a cookie header
content.AddCookie("session", token, "https://api.example.com/orders");
// Or provide the domain and path separately:
content.AddCookie("session", token, "api.example.com", "/orders");
When given an absolute URI and no explicit path, AddCookie() uses the URI host and absolute path. Otherwise, it treats the third argument as a domain and defaults the path to /. The resulting header has the form name=value; Domain=domain; Path=path.
Debug logging
await content.Log(logger, cancellationToken);
Log() reads the complete body as text and writes it at Debug level. It does not read the body when debug logging is disabled. Avoid it for large, binary, credential-bearing, or personally identifiable payloads unless the configured log destination is appropriate for that data.
| Product | Versions 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. |
-
net10.0
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.11)
- Soenneker.Extensions.Stream (>= 4.0.145)
- Soenneker.HttpContents.PooledByteArrays (>= 4.0.16)
- Soenneker.Utils.MemoryStream (>= 4.0.1520)
- Soenneker.Utils.PooledStringBuilders (>= 4.0.28)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on Soenneker.Extensions.HttpContent:
| Package | Downloads |
|---|---|
|
Soenneker.Extensions.HttpResponseMessage
A collection of helpful HttpResponseMessage extension methods |
|
|
Soenneker.Extensions.HttpRequestMessage
A collection of helpful HttpRequestMessage extension methods |
|
|
Soenneker.Renovate.Jobs
A utility library for Mend Renovate job related operations |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.947 | 0 | 8/30/2026 |
| 4.0.946 | 0 | 8/30/2026 |
| 4.0.944 | 0 | 8/30/2026 |
| 4.0.943 | 26 | 8/30/2026 |
| 4.0.941 | 40 | 8/30/2026 |
| 4.0.940 | 37 | 8/30/2026 |
| 4.0.938 | 114 | 8/30/2026 |
| 4.0.937 | 256 | 8/29/2026 |
| 4.0.935 | 223 | 8/29/2026 |
| 4.0.934 | 1,251 | 8/26/2026 |
| 4.0.933 | 35 | 8/26/2026 |
| 4.0.932 | 463 | 8/26/2026 |
| 4.0.931 | 498 | 8/25/2026 |
| 4.0.930 | 1,665 | 8/21/2026 |
| 4.0.929 | 2,161 | 8/18/2026 |
| 4.0.928 | 521 | 8/18/2026 |
| 4.0.927 | 2,085 | 8/13/2026 |
| 4.0.926 | 401 | 8/12/2026 |
| 4.0.925 | 883 | 8/11/2026 |
| 4.0.924 | 1,788 | 8/9/2026 |
Update dependency Soenneker.Extensions.Stream to 4.0.145 (#1301)