System.Net.Http.Headers.RangeConditionHeaderParser

Class Summary

Represents a parser for Range condition headers (If-Range).

Namespace: System.Net.Http.Headers

Assembly: System.Net.Http.Formatting (in System.Net.Http.Formatting.dll)

Inheritance: Object > RangeConditionHeaderParser

Methods

This class has no public methods.

Properties

This class has no public properties.

Constructors

This class has no public constructors.

Remarks

The RangeConditionHeaderParser class is responsible for parsing the value of the If-Range HTTP header. This header is used in conditional requests to specify that a resource should only be transferred if the server's version of the resource matches a given tag or date.

The parser handles two main types of If-Range header values:

When parsing an If-Range header, this parser will attempt to interpret the value as either an ETag or a date. If successful, it will produce an appropriate object representing the condition.

Example Usage

Here's a simple example of how to use the parser (though typically it's used internally by the HTTP client/server stack):


var etagValue = "\"some-etag-value\"";
var dateValue = "Mon, 27 Sep 2021 17:00:00 GMT";

// In a real scenario, these would come from incoming HTTP headers
// and the parser would be invoked by the framework.

try {
    // If-Range with ETag
    var etagCondition = RangeConditionHeaderValue.Parse(etagValue);
    Console.WriteLine($"Parsed ETag Condition: {etagCondition}");

    // If-Range with Date
    var dateCondition = RangeConditionHeaderValue.Parse(dateValue);
    Console.WriteLine($"Parsed Date Condition: {dateCondition}");

} catch (FormatException ex) {
    Console.WriteLine($"Error parsing header: {ex.Message}");
}

// Output might look like:
// Parsed ETag Condition: "some-etag-value"
// Parsed Date Condition: Mon, 27 Sep 2021 17:00:00 GMT
            

See Also