Response_CacheControl.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace System.Net.ApiService {
  5. public class Response_CacheControl {
  6. [Flags]
  7. public enum eCacheControl {
  8. none = 0,
  9. no_cache = 1,
  10. no_store = 2,
  11. no_transform = 4,
  12. must_revalidate = 8,
  13. public_cache = 16,
  14. private_cache = 32,
  15. proxy_revalidate = 64
  16. }
  17. private TimeSpan _maxAge;
  18. private TimeSpan _sMaxAge;
  19. private eCacheControl _options;
  20. public Response_CacheControl(TimeSpan MaxAge) {
  21. this._maxAge = MaxAge;
  22. }
  23. public Response_CacheControl(TimeSpan MaxAge, TimeSpan SMaxAge) {
  24. this._maxAge = MaxAge;
  25. this._sMaxAge = SMaxAge;
  26. }
  27. public Response_CacheControl(TimeSpan MaxAge, eCacheControl Options) {
  28. this._maxAge = MaxAge;
  29. this._options = Options;
  30. }
  31. public Response_CacheControl(eCacheControl Options) {
  32. this._options = Options;
  33. }
  34. public Response_CacheControl(TimeSpan MaxAge, TimeSpan SMaxAge, eCacheControl Options) {
  35. this._maxAge = MaxAge;
  36. this._sMaxAge = SMaxAge;
  37. this._options = Options;
  38. }
  39. public bool IsSet {
  40. get {
  41. return this._maxAge.TotalSeconds > 0 || this._sMaxAge.TotalSeconds > 0 || this._options != eCacheControl.none;
  42. }
  43. }
  44. public TimeSpan MaxAge {
  45. get => this._maxAge;
  46. set {
  47. if (value == null) {
  48. this._maxAge = new TimeSpan(0);
  49. } else {
  50. this._maxAge = value;
  51. }
  52. }
  53. }
  54. public TimeSpan SMaxAge {
  55. get => this._sMaxAge;
  56. set {
  57. if (value == null) {
  58. this._sMaxAge = new TimeSpan(0);
  59. } else {
  60. this._sMaxAge = value;
  61. }
  62. }
  63. }
  64. public eCacheControl Options {
  65. get => this._options;
  66. set {
  67. this._options = value;
  68. }
  69. }
  70. public override string ToString() {
  71. string s = "";
  72. if (this._maxAge.TotalSeconds > 0)
  73. s += (s==""?"":", ") + "max-age: " + this._maxAge.TotalSeconds;
  74. if (this._sMaxAge.TotalSeconds > 0)
  75. s += (s == "" ? "" : ", ") + "s-maxage: " + this._maxAge.TotalSeconds;
  76. if (this._options != eCacheControl.none) {
  77. if((this._options & eCacheControl.must_revalidate) == this._options)
  78. s += (s == "" ? "" : ", ") + "must-revalidate";
  79. if ((this._options & eCacheControl.no_cache) == this._options)
  80. s += (s == "" ? "" : ", ") + "no-cache";
  81. if ((this._options & eCacheControl.no_store) == this._options)
  82. s += (s == "" ? "" : ", ") + "no-store";
  83. if ((this._options & eCacheControl.no_transform) == this._options)
  84. s += (s == "" ? "" : ", ") + "no-transform";
  85. if ((this._options & eCacheControl.private_cache) == this._options)
  86. s += (s == "" ? "" : ", ") + "private";
  87. if ((this._options & eCacheControl.public_cache) == this._options)
  88. s += (s == "" ? "" : ", ") + "public";
  89. if ((this._options & eCacheControl.proxy_revalidate) == this._options)
  90. s += (s == "" ? "" : ", ") + "proxy-revalidate";
  91. }
  92. return s;
  93. }
  94. }
  95. }