Represents a transfer coding header value. Transfer codings are used to add or remove data transformations from an HTTP message body without altering the content coding.
public sealed class TransferCodingHeaderValue
TransferCodingHeaderValue(string encodedTransferCoding)Initializes a new instance of the TransferCodingHeaderValue class with a specified encoded transfer coding value.
var transferCoding = new TransferCodingHeaderValue("chunked");
TransferCodingHeaderValue(TransferCodingHeaderValue other)Initializes a new instance of the TransferCodingHeaderValue class with a copy of another TransferCodingHeaderValue instance.
var original = new TransferCodingHeaderValue("gzip");
var copy = new TransferCodingHeaderValue(original);
| Name | Description |
|---|---|
Parameters |
Gets a collection of parameters for the transfer coding. These are represented as NameValueHeaderValue objects. |
Equals(object obj)Determines whether the specified object is equal to the current object.
GetHashCode()Serves as the default hash function.
Parse(string input)Parses a transfer coding header value from the specified string.
var transferCoding = TransferCodingHeaderValue.Parse("chunked, identity; q=0.5");
ToString()Returns a string that represents the current object.
var transferCoding = new TransferCodingHeaderValue("compress");
Console.WriteLine(transferCoding.ToString()); // Output: compress
TryParse(string input, out TransferCodingHeaderValue parsedValue)Tries to parse a transfer coding header value from the specified string.
TransferCodingHeaderValue parsed;
if (TransferCodingHeaderValue.TryParse("deflate; level=6", out parsed))
{
Console.WriteLine($"Parsed transfer coding: {parsed}");
}
var request = new HttpRequestMessage(HttpMethod.Get, "http://example.com");
request.Headers.TransferEncodingChunked = true; // Shortcut for adding "chunked"
// Or manually:
var transferCoding = new TransferCodingHeaderValue("gzip");
transferCoding.Parameters.Add(new NameValueHeaderValue("q", "0.8"));
request.Headers.TransferEncoding.Add(transferCoding);
var response = new HttpResponseMessage();
response.Content = new StringContent("Some data");
// Typically, the server or framework handles setting this based on Content-Encoding
if (response.Content.Headers.ContentEncoding.Contains("gzip"))
{
Console.WriteLine("Content is gzipped.");
}