Class HttpContentExtensions
- Namespace
- Kampute.HttpClient
- Assembly
- Kampute.HttpClient.dll
Provides extension methods for HttpContent to enhance functionality related to HTTP content processing.
public static class HttpContentExtensions
- Inheritance
-
HttpContentExtensions
- Inherited Members
Methods
AsDeflate(HttpContent, CompressionLevel)
Compresses the HttpContent using the Deflate compression algorithm.
public static DeflateCompressedContent AsDeflate(this HttpContent httpContent, CompressionLevel compressionLevel = CompressionLevel.Optimal)
Parameters
httpContent
HttpContentThe HTTP content to compress.
compressionLevel
CompressionLevelThe 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(HttpContent, CompressionLevel)
Compresses the HttpContent using the GZIP compression algorithm.
public static GzipCompressedContent AsGzip(this HttpContent httpContent, CompressionLevel compressionLevel = CompressionLevel.Optimal)
Parameters
httpContent
HttpContentThe HTTP content to compress.
compressionLevel
CompressionLevelThe 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(HttpContent)
Attempts to find the character encoding from the HttpContent headers.
public static Encoding? FindCharacterEncoding(this HttpContent httpContent)
Parameters
httpContent
HttpContentThe 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.
Remarks
This method inspects the 'CharSet' value in the content type header of the HttpContent. If the charset is specified and recognized, it returns the corresponding Encoding. If the charset is not specified, the method returns null, indicating that the encoding could not be determined. An ArgumentException is thrown if the charset is specified but not supported by the system.
Exceptions
- ArgumentException
Thrown if the charset specified in the content's headers is not recognized.
IsReusable(HttpContent)
Determines whether the HttpContent instance can be reused.
public static bool IsReusable(this HttpContent httpContent)
Parameters
httpContent
HttpContentThe 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.