GenericHeaderValueSegment Class

Represents a generic header value segment within an HTTP header. This class is typically used internally by the .NET Framework to parse and represent complex header values that consist of multiple segments and parameters.

Namespace

System.Net.Http.Headers

Assembly

System.Net.Http.dll

Inheritance

Methods

Properties

Remarks

This class is primarily used by the HttpContentHeaders and HttpResponseHeaders collections when parsing complex header values such as those found in `Accept`, `Content-Type`, or `Set-Cookie` headers.

For example, a header like application/json; charset=utf-8; version=1.0 would be parsed into segments. `application/json` might be the primary value, and `charset=utf-8` and `version=1.0` would be its associated parameters.

Example Usage (Conceptual)

While you typically don't instantiate GenericHeaderValueSegment directly, it's useful to understand how it's used internally.

// This is conceptual and shows internal parsing logic var header = "application/json; charset=utf-8; version=1.0"; // Internally, .NET might parse this into segments and parameters // Imagine a parsed segment object: var segment = new GenericHeaderValueSegment( "application/json", new List<NameValueHeaderValue> { new NameValueHeaderValue("charset", "utf-8"), new NameValueHeaderValue("version", "1.0") } ); Console.WriteLine(segment.Name); // Output: application/json foreach (var param in segment.Parameters) { Console.WriteLine($"{param.Name}: {param.Value}"); } // Output: // charset: utf-8 // version: 1.0