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.
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.
Gets a TransferEncodingHeaderValue object that represents the chunked transfer coding.
Initializes a new instance of the TransferEncodingHeaderValue class.
Initializes a new instance of the TransferEncodingHeaderValue class with the specified transfer coding name.
Parses a Transfer-Encoding header value from a string.
Tries to parse a Transfer-Encoding header value from a string.
Returns a string representation of the TransferEncodingHeaderValue object.
Gets the collection of transfer coding qualifiers for this TransferEncodingHeaderValue object.
Gets the name of the transfer coding.
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
}