HttpContentExtensions Class
- Namespace
- Kampute.HttpClient
- Assembly
- Kampute.HttpClient.dll
Definition
Provides extension methods for HttpContent.
public static class HttpContentExtensions- Inheritance
- object
- HttpContentExtensions
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
httpContentHttpContent- The content to compress. It is disposed when the returned content is disposed.
compressionLevelCompressionLevel 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
httpContentHttpContent- The content to compress. It is disposed when the returned content is disposed.
compressionLevelCompressionLevel 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
httpContentHttpContent- The content whose encoding to return.
Returns
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
httpContentHttpContent- The content to check.
Returns
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.
