HttpContentExtensions Class

Namespace
Kampute.HttpClient
Assembly
  • Kampute.HttpClient.dll

Definition

Provides extension methods for HttpContent.
public static class HttpContentExtensions
Inheritance

Methods

AsDeflate(this HttpContent, CompressionLevel)

Wraps the content in content that compresses it with Deflate as it is sent.
public static DeflateCompressedContent AsDeflate(this HttpContent httpContent, CompressionLevel compressionLevel = CompressionLevel.Optimal)

Parameters

httpContent HttpContent
The content to compress. It is disposed when the returned content is disposed.
compressionLevel CompressionLevel optional
Whether to favor speed or size. The default is CompressionLevel.Optimal.

Returns

DeflateCompressedContent
A DeflateCompressedContent that wraps httpContent.

AsGzip(this HttpContent, CompressionLevel)

Wraps the content in content that compresses it with GZip as it is sent.
public static GzipCompressedContent AsGzip(this HttpContent httpContent, CompressionLevel compressionLevel = CompressionLevel.Optimal)

Parameters

httpContent HttpContent
The content to compress. It is disposed when the returned content is disposed.
compressionLevel CompressionLevel optional
Whether to favor speed or size. The default is CompressionLevel.Optimal.

Returns

GzipCompressedContent
A GzipCompressedContent that wraps httpContent.

FindCharacterEncoding(this HttpContent)

Returns the character encoding named by the charset parameter of the Content-Type header.
public static Encoding FindCharacterEncoding(this HttpContent httpContent)

Parameters

httpContent HttpContent
The content whose encoding to return.

Returns

Encoding
The Encoding that the header names, or null if the header names none.

Exceptions

ArgumentException
Thrown if the header names a character set that the runtime does not support.

IsReusable(this HttpContent)

Determines whether the content can be sent more than once, as a retry requires.
public static bool IsReusable(this HttpContent httpContent)

Parameters

httpContent HttpContent
The content to check.

Returns

bool
true if the content can be sent again; otherwise, false.

Remarks

A StreamContent can be sent again only if its length is known, which is the case for a seekable stream; a non-seekable stream can be read only once. Content that wraps another content, such as compressed content, can be sent again if the wrapped content can. Other content is assumed to be reusable.