RangeConditionHeaderParser Class

System.Net.Http.Headers

Represents a parser for the Range condition header.

// Definition
public static class RangeConditionHeaderParser

Members

Methods

Name Description
static bool TryParse(string input, out RangeConditionHeaderValue? headerValue)
Tries to parse a string into a RangeConditionHeaderValue object.

Remarks

The RangeConditionHeaderParser class is used internally by the .NET framework to parse the Range header in HTTP requests. It is not intended for direct use by developers. The header value is typically parsed into a RangeConditionHeaderValue object, which can then be used to determine the requested byte range for a resource.

Examples

While not intended for direct use, the following example demonstrates how the underlying parsing logic might be invoked (this is for illustrative purposes only and relies on internal implementation details).

using System;
using System.Net.Http.Headers;

public class Example
{
public static void Main(string[] args)
{
string headerString = "bytes=0-499";
RangeConditionHeaderValue condition;

if (RangeConditionHeaderParser.TryParse(headerString, out condition))
{
Console.WriteLine($"Successfully parsed: {condition}");
Console.WriteLine($"Range: {condition.Range.Unit}-<{condition.Range.Ranges.Count}");
foreach (var range in condition.Range.Ranges)
{
Console.WriteLine($" Start: {range.From}, End: {range.To}");
}
}
else
{
Console.WriteLine("Failed to parse Range header.");
}
}
}

See Also