System.Net.Http.Headers

.NET API Documentation

TransferEncodingHeaderValue Class

System.Net.Http.Headers

Summary

Represents a Transfer-Encoding header value.

The Transfer-Encoding header is used to indicate the transfer encoding mechanism that has been applied to the payload body. This header is a general-header because it applies to the message body whether or not it is enclosed in an entity-body.

Syntax

public sealed class TransferEncodingHeaderValue : ICloneable
public sealed class TransferEncodingHeaderValue : IEquatable<TransferEncodingHeaderValue>

Remarks

The Transfer-Encoding header is used by HTTP servers and clients to communicate how the HTTP message body is encoded. Common transfer encodings include chunked, which allows the sender to transmit the message body as a series of chunks of unknown length, and gzip, which compresses the message body.

When multiple transfer codings are present, they are applied in the order they appear in the header. For example, Transfer-Encoding: gzip, chunked indicates that the body is first compressed with gzip and then chunked.

This class provides methods to parse and manipulate Transfer-Encoding header values, ensuring compliance with HTTP specifications.

Requirements

Namespace: System.Net.Http.Headers

Assembly: System.Net.Http.dll

Frameworks: Supports .NET Framework 4.5, .NET Core 1.0, .NET Standard 1.3, and later versions.

Members

Name Description
Parse(string) Parses a Transfer-Encoding header value.
TryParse(string, out TransferEncodingHeaderValue) Tries to parse a Transfer-Encoding header value.
Encoding Gets the transfer coding name.
Parameters Gets the parameters associated with the transfer coding.
ToString() Returns the string representation of the Transfer-Encoding header value.
GetHashCode() Gets the hash code for the current object.
Equals(object) Determines whether the specified object is equal to the current object.
Equals(TransferEncodingHeaderValue) Determines whether the specified TransferEncodingHeaderValue is equal to the current object.

Parse(string)

Description: Parses a string into a TransferEncodingHeaderValue instance.

Syntax:

public static TransferEncodingHeaderValue Parse(string input);

Parameters:

  • input: The string to parse.

Returns: A TransferEncodingHeaderValue instance created from the input string.

Throws: FormatException if the input is not a valid Transfer-Encoding header value.

TryParse(string, out TransferEncodingHeaderValue)

Description: Tries to parse a string into a TransferEncodingHeaderValue instance without throwing an exception.

Syntax:

public static bool TryParse(string input, out TransferEncodingHeaderValue result);

Parameters:

  • input: The string to parse.
  • result: When this method returns, contains the parsed TransferEncodingHeaderValue instance, if the parse was successful.

Returns: true if the input was parsed successfully; otherwise, false.

Encoding

Description: Gets the transfer coding name (e.g., "chunked", "gzip").

Syntax:

public string Encoding { get; }

Value: The transfer coding name.

Parameters

Description: Gets the parameters associated with the transfer coding as a collection of NameValueHeaderValue objects.

Syntax:

public IList<NameValueHeaderValue> Parameters { get; }

Value: A read-only list of parameters.

ToString()

Description: Returns the canonical string representation of the TransferEncodingHeaderValue.

Syntax:

public override string ToString();

Returns: A string that represents the current object.

GetHashCode()

Description: Computes the hash code for the current TransferEncodingHeaderValue instance.

Syntax:

public override int GetHashCode();

Returns: A hash code for the current object.

Equals(object)

Description: Determines whether the specified object is equal to the current object.

Syntax:

public override bool Equals(object obj);

Parameters:

  • obj: The object to compare with the current object.

Returns: true if the specified object is equal to the current object; otherwise, false.

Equals(TransferEncodingHeaderValue)

Description: Determines whether the specified TransferEncodingHeaderValue is equal to the current object.

Syntax:

public bool Equals(TransferEncodingHeaderValue other);

Parameters:

  • other: The TransferEncodingHeaderValue to compare with the current object.

Returns: true if the specified TransferEncodingHeaderValue is equal to the current object; otherwise, false.