namespace System.Net.Http.Headers
Represents a Range condition header value. This class is used to specify a condition that must be met for a range of data to be returned. It is typically used with the Range header and conditional request headers like If-Match, If-None-Match, If-Modified-Since, and If-Unmodified-Since.
The Range condition header can be constructed using either a date-time value or an entity tag value.
RangeConditionHeaderValue class with the specified date.
RangeConditionHeaderValue class with the specified entity tag.
null if the condition is based on an entity tag.
null if the condition is based on a date.
using System;
using System.Net.Http.Headers;
// Example date
DateTimeOffset lastModified = new DateTimeOffset(2023, 10, 27, 10, 30, 0, TimeSpan.Zero);
// Create the header value
RangeConditionHeaderValue condition = new RangeConditionHeaderValue(lastModified);
Console.WriteLine($"Condition: {condition}");
// Output: Condition: Tue, 27 Oct 2023 10:30:00 GMT
using System;
using System.Net.Http.Headers;
// Example entity tag
string etag = "\"some-etag-value\"";
// Create the header value
RangeConditionHeaderValue condition = new RangeConditionHeaderValue(etag);
Console.WriteLine($"Condition: {condition}");
// Output: Condition: "some-etag-value"
using System;
using System.Net.Http.Headers;
string inputDate = "Tue, 27 Oct 2023 10:30:00 GMT";
if (RangeConditionHeaderValue.TryParse(inputDate, out RangeConditionHeaderValue conditionFromDate))
{
Console.WriteLine($"Parsed Date Condition: {conditionFromDate.Date}");
// Output: Parsed Date Condition: 10/27/2023 10:30:00 AM +00:00
}
string inputEtag = "\"another-etag\"";
if (RangeConditionHeaderValue.TryParse(inputEtag, out RangeConditionHeaderValue conditionFromEtag))
{
Console.WriteLine($"Parsed ETag Condition: {conditionFromEtag.EntityTag}");
// Output: Parsed ETag Condition: "another-etag"
}
This class is immutable, meaning its state cannot be changed after it is created. This ensures thread safety.
When using the RangeConditionHeaderValue with conditional HTTP requests, the server will return the requested resource only if the condition specified in the header is met. For example, if you use a date condition, the resource will be returned only if it has been modified since that date.