HttpLifetimeHeaderValueSegment Class

Represents a segment in a lifetime header value, which can be a numeric value or a named parameter.

Namespace

System.Net.Http.Headers

Assembly

System.Net.Http.dll

Syntax
public sealed class HttpLifetimeHeaderValueSegment
Remarks

This class is used internally by the .NET HTTP headers parsing mechanism to represent individual components of lifetime headers, such as the `Max-Age` directive in the `Cache-Control` header. It allows for flexible parsing of header values that can consist of numbers and optional name-value pairs.

Properties
  • Value

    public long Value { get; }

    Gets the numeric value of the segment.

  • Name

    public string Name { get; }

    Gets the name of the parameter associated with the numeric value. This will be null if the segment only contains a numeric value.

Constructors
  • HttpLifetimeHeaderValueSegment

    public HttpLifetimeHeaderValueSegment(long value)

    Initializes a new instance of the HttpLifetimeHeaderValueSegment class with only a numeric value.

  • HttpLifetimeHeaderValueSegment

    public HttpLifetimeHeaderValueSegment(long value, string name)

    Initializes a new instance of the HttpLifetimeHeaderValueSegment class with a numeric value and an optional parameter name.

Methods
  • ToString

    public override string ToString()

    Returns a string representation of the HttpLifetimeHeaderValueSegment object.

Examples

Here's a conceptual example of how this class might be used internally when parsing a header like Cache-Control: max-age=3600, public.

// Imagine a parser that produces these segments: var maxAgeSegment = new HttpLifetimeHeaderValueSegment(3600, "max-age"); var publicSegment = new HttpLifetimeHeaderValueSegment(0, "public"); // Assuming "public" might be parsed with a default value or as a flag. Console.WriteLine(maxAgeSegment.ToString()); // Output: max-age=3600 Console.WriteLine(publicSegment.ToString()); // Output: public