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
Inherited by

Remarks

The content has the headers of the content it compresses, except Content-Length and Content-MD5, which describe the uncompressed body. It adds its encoding to the Content-Encoding header, and its length is not known until it is sent, so it is sent without a Content-Length header, which over HTTP/1.1 means chunked transfer encoding.

Constructors

CompressedContent(HttpContent, string)

Initializes a new instance of the CompressedContent class.
protected CompressedContent(HttpContent content, string contentEncoding)

Parameters

content HttpContent
The content to compress. It is disposed when this instance is disposed.
contentEncoding string
The value added to the Content-Encoding header, such as gzip or deflate.

Exceptions

ArgumentNullException
Thrown when content is null.
ArgumentException
Thrown when contentEncoding is null or 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

stream Stream
The stream that receives the compressed data.

Returns

Stream
A Stream that compresses the data written to it into stream.

SerializeToStreamAsync(Stream, TransportContext)

Writes the compressed content to a stream.
protected sealed override Task SerializeToStreamAsync(Stream stream, TransportContext context)

Parameters

stream Stream
The stream to write to.
context TransportContext
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

length long
Always -1.

Returns

bool
Always false.

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.