You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

HTTPRange.cs 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. namespace BestHTTP
  3. {
  4. /// <summary>
  5. ///
  6. /// </summary>
  7. public sealed class HTTPRange
  8. {
  9. /// <summary>
  10. /// The first byte's position that the server sent.
  11. /// </summary>
  12. public int FirstBytePos { get; private set; }
  13. /// <summary>
  14. /// The last byte's position that the server sent.
  15. /// </summary>
  16. public int LastBytePos { get; private set; }
  17. /// <summary>
  18. /// Indicates the total length of the full entity-body on the server, -1 if this length is unknown or difficult to determine.
  19. /// </summary>
  20. public int ContentLength { get; private set; }
  21. /// <summary>
  22. ///
  23. /// </summary>
  24. public bool IsValid { get; private set; }
  25. internal HTTPRange()
  26. {
  27. this.ContentLength = -1;
  28. this.IsValid = false;
  29. }
  30. internal HTTPRange(int contentLength)
  31. {
  32. this.ContentLength = contentLength;
  33. this.IsValid = false;
  34. }
  35. internal HTTPRange(int firstBytePosition, int lastBytePosition, int contentLength)
  36. {
  37. this.FirstBytePos = firstBytePosition;
  38. this.LastBytePos = lastBytePosition;
  39. this.ContentLength = contentLength;
  40. // 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.
  41. this.IsValid = this.FirstBytePos <= this.LastBytePos && this.ContentLength > this.LastBytePos;
  42. }
  43. public override string ToString()
  44. {
  45. return string.Format("{0}-{1}/{2} (valid: {3})", FirstBytePos, LastBytePos, ContentLength, IsValid);
  46. }
  47. }
  48. }