HttpCacheVaryByHeaders.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. //
  2. // System.Web.HttpCacheVaryByHeaders
  3. //
  4. // Author:
  5. // Patrik Torstensson ([email protected])
  6. //
  7. using System;
  8. using System.Collections;
  9. namespace System.Web {
  10. public sealed class HttpCacheVaryByHeaders {
  11. private Hashtable _Items;
  12. private bool _Dirty;
  13. private bool _Wildcard;
  14. // TODO: We need internal methods here to communicate with CachePolicy
  15. internal HttpCacheVaryByHeaders() {
  16. }
  17. public void VaryByUnspecifiedParameters() {
  18. _Dirty = true;
  19. _Wildcard = true;
  20. _Items = null;
  21. }
  22. public bool AcceptTypes {
  23. get {
  24. return this["Accept"];
  25. }
  26. set {
  27. this["Accept"] = value;
  28. }
  29. }
  30. public bool this[string header] {
  31. get {
  32. if (null == header) {
  33. throw new ArgumentNullException("header");
  34. }
  35. if (header == "*") {
  36. return _Wildcard;
  37. }
  38. if (null != _Items) {
  39. return _Items.ContainsKey(header);
  40. }
  41. return false;
  42. }
  43. set {
  44. if (null == header) {
  45. throw new ArgumentNullException("header");
  46. }
  47. if (!(value)) {
  48. return;
  49. }
  50. _Dirty = true;
  51. if (header == "*") {
  52. VaryByUnspecifiedParameters();
  53. return;
  54. }
  55. if (!_Wildcard) {
  56. if (null == _Items) {
  57. _Items = new Hashtable();
  58. }
  59. _Items[header] = true;
  60. }
  61. }
  62. }
  63. public bool UserAgent {
  64. get {
  65. return this["User-Agent"];
  66. }
  67. set {
  68. this["User-Agent"] = value;
  69. }
  70. }
  71. public bool UserCharSet {
  72. get {
  73. return this["Accept-Charset"];
  74. }
  75. set {
  76. this["Accept-Charset"] = value;
  77. }
  78. }
  79. public bool UserLanguage {
  80. get {
  81. return this["Accept-Language"];
  82. }
  83. set {
  84. this["Accept-Language"] = value;
  85. }
  86. }
  87. }
  88. }