HttpLifetimeHeaderValueSegment Class
Represents a segment in a lifetime header value, which can be a numeric value or a named parameter.
System.Net.Http.dll
public sealed class HttpLifetimeHeaderValueSegment
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.
-
HttpLifetimeHeaderValueSegment
public HttpLifetimeHeaderValueSegment(long value)Initializes a new instance of the
HttpLifetimeHeaderValueSegmentclass with only a numeric value. -
HttpLifetimeHeaderValueSegment
public HttpLifetimeHeaderValueSegment(long value, string name)Initializes a new instance of the
HttpLifetimeHeaderValueSegmentclass with a numeric value and an optional parameter name.
-
ToString
public override string ToString()Returns a string representation of the
HttpLifetimeHeaderValueSegmentobject.
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