System.Net.Http.Headers.TransferEncodingHeaderValue

Namespace: System.Net.Http.Headers

TransferEncodingHeaderValue

Represents a Transfer-Encoding header value.

The Transfer-Encoding header is used to indicate that the message body has undergone transformations, such as compression. The value is a list of transfer coding names, with the innermost encoding listed first.

Remarks

The Transfer-Encoding header is used by HTTP to indicate the type of encoding applied to the message body. Common transfer codings include chunked and gzip.

This class provides methods to parse and manage the Transfer-Encoding header value.

Fields

Constructors

Methods

Properties

Example Usage


using System.Net.Http.Headers;

// Creating a chunked transfer encoding
var chunkedEncoding = TransferEncodingHeaderValue.Chunked;
Console.WriteLine(chunkedEncoding.ToString()); // Output: chunked

// Creating a custom transfer encoding
var customEncoding = new TransferEncodingHeaderValue("gzip");
customEncoding.EncodingQualifiers.Add("q=0.5"); // Optional qualifier
Console.WriteLine(customEncoding.ToString()); // Output: gzip; q=0.5

// Parsing a header value
string headerString = "deflate, gzip;q=0.8";
if (TransferEncodingHeaderValue.TryParse(headerString, out var parsedEncoding))
{
    Console.WriteLine("Parsed Transfer-Encoding: " + parsedEncoding.ToString());
    // You can further inspect parsedEncoding.Name and parsedEncoding.EncodingQualifiers
}