CompressedContent Class
- Namespace
- Kampute.HttpClient.Content.Compression.Abstracts
- Assembly
- Kampute.HttpClient.dll
Definition
Provides a base class for content that compresses another HttpContent as it is sent.
public abstract class CompressedContent : HttpContentDecorator- Inheritance
- object
- HttpContent
- HttpContentDecorator
- CompressedContent
- Inherited by
Remarks
Constructors
CompressedContent(HttpContent, string)
Initializes a new instance of the CompressedContent class.
protected CompressedContent(HttpContent content, string contentEncoding)Parameters
contentHttpContent- The content to compress. It is disposed when this instance is disposed.
contentEncodingstring- The value added to the
Content-Encodingheader, such asgzipordeflate.
Exceptions
- ArgumentNullException
- Thrown when
contentisnull. - ArgumentException
- Thrown when
contentEncodingisnullor empty.
Methods
CompressStream(Stream)
When overridden in a derived class, returns a stream that compresses the data written to it into the specified stream.
protected abstract Stream CompressStream(Stream stream)Parameters
streamStream- The stream that receives the compressed data.
Returns
SerializeToStreamAsync(Stream, TransportContext)
Writes the compressed content to a stream.
protected sealed override Task SerializeToStreamAsync(Stream stream, TransportContext context)Parameters
streamStream- The stream to write to.
contextTransportContext- The transport context.
Returns
- Task
- A task that represents the asynchronous operation.
TryComputeLength(out long)
Indicates that the length of the compressed content is not known before it is sent.
protected sealed override bool TryComputeLength(out long length)Parameters
lengthlong- Always -1.
Returns
Extension Methods
| AsDeflate(this HttpContent, CompressionLevel) | Wraps the content in content that compresses it with Deflate as it is sent. |
| AsGzip(this HttpContent, CompressionLevel) | Wraps the content in content that compresses it with GZip as it is sent. |
| FindCharacterEncoding(this HttpContent) | Returns the character encoding named by the charset parameter of the Content-Type header. |
| IsReusable(this HttpContent) | Determines whether the content can be sent more than once, as a retry requires. |

Content-LengthandContent-MD5, which describe the uncompressed body. It adds its encoding to theContent-Encodingheader, and its length is not known until it is sent, so it is sent without aContent-Lengthheader, which over HTTP/1.1 means chunked transfer encoding.