TransferEncodingParser Class

Represents a parser for the Transfer-Encoding header.

Remarks

The Transfer-Encoding header is used to indicate the type of transfer encoding applied to the message. This header is a hop-by-hop header that is intended only for a transport-level mechanism and must be removed or replaced by the relevant transport-level context.

The TransferEncodingParser class provides functionality to parse and validate the format of the Transfer-Encoding header according to RFC 7230 and RFC 9110.

Syntax


public static class TransferEncodingParser
                    

Methods

Name Description
Parse Parses a Transfer-Encoding header value and returns a TransferCodingHeaderValue object.
TryParse Attempts to parse a Transfer-Encoding header value without throwing an exception.

Usage Example


using System;
using System.Net.Http.Headers;

public class Example
{
    public static void Main(string[] args)
    {
        string headerValue = "chunked, gzip";
        TransferCodingHeaderValue transferEncoding;

        if (TransferEncodingParser.TryParse(headerValue, out transferEncoding))
        {
            Console.WriteLine("Successfully parsed Transfer-Encoding header:");
            Console.WriteLine($"  Encoding: {transferEncoding.Value}");
            // You can access parameters if any
            foreach (var param in transferEncoding.Parameters)
            {
                Console.WriteLine($"  Parameter: {param.Name}={param.Value}");
            }
        }
        else
        {
            Console.WriteLine("Failed to parse Transfer-Encoding header.");
        }
    }
}
                    

See Also