CachedRawResponse.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. //
  2. // System.Web.Caching.CachedRawResponse
  3. //
  4. // Author(s):
  5. // Jackson Harper ([email protected])
  6. // Marek Habersack <[email protected]>
  7. //
  8. // (C) 2003-2009 Novell, Inc (http://www.novell.com)
  9. //
  10. //
  11. // Permission is hereby granted, free of charge, to any person obtaining
  12. // a copy of this software and associated documentation files (the
  13. // "Software"), to deal in the Software without restriction, including
  14. // without limitation the rights to use, copy, modify, merge, publish,
  15. // distribute, sublicense, and/or sell copies of the Software, and to
  16. // permit persons to whom the Software is furnished to do so, subject to
  17. // the following conditions:
  18. //
  19. // The above copyright notice and this permission notice shall be
  20. // included in all copies or substantial portions of the Software.
  21. //
  22. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. //
  30. using System;
  31. using System.Collections;
  32. using System.Collections.Specialized;
  33. using System.IO;
  34. using System.Text;
  35. using System.Collections.Generic;
  36. namespace System.Web.Caching
  37. {
  38. sealed class CachedRawResponse
  39. {
  40. public sealed class DataItem
  41. {
  42. public readonly byte[] Buffer;
  43. public readonly long Length;
  44. public readonly HttpResponseSubstitutionCallback Callback;
  45. public DataItem (byte[] buffer, long length)
  46. {
  47. Buffer = buffer;
  48. Length = length;
  49. }
  50. public DataItem (HttpResponseSubstitutionCallback callback) : this (null, 0)
  51. {
  52. Callback = callback;
  53. }
  54. }
  55. HttpCachePolicy policy;
  56. CachedVaryBy varyby;
  57. int status_code;
  58. string status_desc;
  59. NameValueCollection headers;
  60. List <DataItem> data;
  61. IList Data {
  62. get {
  63. if (data == null)
  64. data = new List <DataItem> ();
  65. return data;
  66. }
  67. }
  68. public CachedRawResponse (HttpCachePolicy policy)
  69. {
  70. this.policy = policy;
  71. }
  72. public HttpCachePolicy Policy {
  73. get { return policy; }
  74. set { policy = value; }
  75. }
  76. public CachedVaryBy VaryBy {
  77. get { return varyby; }
  78. set { varyby = value; }
  79. }
  80. public int StatusCode {
  81. get { return status_code; }
  82. set { status_code = value; }
  83. }
  84. public string StatusDescription {
  85. get { return status_desc; }
  86. set { status_desc = value; }
  87. }
  88. public NameValueCollection Headers {
  89. get { return headers; }
  90. }
  91. public void SetHeaders (NameValueCollection headers)
  92. {
  93. this.headers = headers;
  94. }
  95. public void SetData (MemoryStream ms)
  96. {
  97. if (ms == null)
  98. return;
  99. Data.Add (new DataItem (ms.GetBuffer (), ms.Length));
  100. }
  101. public void SetData (HttpResponseSubstitutionCallback callback)
  102. {
  103. if (callback == null)
  104. return;
  105. Data.Add (new DataItem (callback));
  106. }
  107. public IList GetData ()
  108. {
  109. int count = data != null ? data.Count :0;
  110. if (count == 0)
  111. return null;
  112. return data;
  113. }
  114. }
  115. }