- Initial commit

This commit is contained in:
Timur Kozanov
2026-07-03 05:02:26 +03:00
commit 374ff1e689
4080 changed files with 388870 additions and 0 deletions

55
Runtime/HTTP/HTTPRange.cs Normal file
View File

@ -0,0 +1,55 @@
namespace Best.HTTP
{
/// <summary>
/// Represents an HTTP range that specifies the byte range of a response content, received as an answer for a range-request.
/// </summary>
public sealed class HTTPRange
{
/// <summary>
/// Gets the position of the first byte in the range that the server sent.
/// </summary>
public long FirstBytePos { get; private set; }
/// <summary>
/// Gets the position of the last byte in the range that the server sent.
/// </summary>
public long LastBytePos { get; private set; }
/// <summary>
/// Gets the total length of the full entity-body on the server. Returns -1 if this length is unknown or difficult to determine.
/// </summary>
public long ContentLength { get; private set; }
/// <summary>
/// Gets a value indicating whether the HTTP range is valid.
/// </summary>
public bool IsValid { get; private set; }
internal HTTPRange()
{
this.ContentLength = -1;
this.IsValid = false;
}
internal HTTPRange(int contentLength)
{
this.ContentLength = contentLength;
this.IsValid = false;
}
internal HTTPRange(long firstBytePosition, long lastBytePosition, long contentLength)
{
this.FirstBytePos = firstBytePosition;
this.LastBytePos = lastBytePosition;
this.ContentLength = contentLength;
// A byte-content-range-spec with a byte-range-resp-spec whose last-byte-pos value is less than its first-byte-pos value, or whose instance-length value is less than or equal to its last-byte-pos value, is invalid.
this.IsValid = this.FirstBytePos <= this.LastBytePos && this.ContentLength > this.LastBytePos;
}
public override string ToString()
{
return string.Format("{0}-{1}/{2} (valid: {3})", FirstBytePos, LastBytePos, ContentLength, IsValid);
}
}
}