HttpContentExtensions Class
- Namespace
- Kampute.HttpClient
- Assembly
- Kampute.HttpClient.dll
Definition
Provides extension methods for HttpContent to enhance functionality related to HTTP content processing.
public static class HttpContentExtensions- Inheritance
- object
- HttpContentExtensions
Methods
AsDeflate(this HttpContent, CompressionLevel)
Compresses the HttpContent using the Deflate compression algorithm.
public static DeflateCompressedContent AsDeflate(this HttpContent httpContent, CompressionLevel compressionLevel = CompressionLevel.Optimal)Parameters
httpContentHttpContent- The HTTP content to compress.
compressionLevelCompressionLevel optional- The level of compression that indicates whether to emphasize speed or compression efficiency.
Returns
- DeflateCompressedContent
- A new instance of DeflateCompressedContent that wraps the original HTTP content with Deflate compression.
AsGzip(this HttpContent, CompressionLevel)
Compresses the HttpContent using the GZIP compression algorithm.
public static GzipCompressedContent AsGzip(this HttpContent httpContent, CompressionLevel compressionLevel = CompressionLevel.Optimal)Parameters
httpContentHttpContent- The HTTP content to compress.
compressionLevelCompressionLevel optional- The level of compression that indicates whether to emphasize speed or compression efficiency.
Returns
- GzipCompressedContent
- A new instance of GzipCompressedContent that wraps the original HTTP content with GZIP compression.
FindCharacterEncoding(this HttpContent)
Attempts to find the character encoding from the HttpContent headers.
public static Encoding FindCharacterEncoding(this HttpContent httpContent)Parameters
httpContentHttpContent- The HttpContent instance to extract the character encoding from.
Returns
- Encoding
- The Encoding specified in the content's headers if the charset is recognized; otherwise,
null.
Exceptions
- ArgumentException
- Thrown if the charset specified in the content's headers is not recognized.
Remarks
IsReusable(this HttpContent)
Determines whether the HttpContent instance can be reused.
public static bool IsReusable(this HttpContent httpContent)Parameters
httpContentHttpContent- The HttpContent instance to check for re-usability.
Returns
Remarks
Reusability of HttpContent is determined by its ability to provide its content multiple times without alteration. For example, content backed by a non-seekable stream is not reusable as the stream can be consumed only once.

null, indicating that the encoding could not be determined. An ArgumentException is thrown if the charset is specified but not supported by the system.