CachedRawResponse.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. #if NET_2_0
  36. using System.Collections.Generic;
  37. #endif
  38. namespace System.Web.Caching
  39. {
  40. sealed class CachedRawResponse
  41. {
  42. public sealed class DataItem
  43. {
  44. public readonly byte[] Buffer;
  45. public readonly long Length;
  46. #if NET_2_0
  47. public readonly HttpResponseSubstitutionCallback Callback;
  48. #endif
  49. public DataItem (byte[] buffer, long length)
  50. {
  51. Buffer = buffer;
  52. Length = length;
  53. }
  54. #if NET_2_0
  55. public DataItem (HttpResponseSubstitutionCallback callback) : this (null, 0)
  56. {
  57. Callback = callback;
  58. }
  59. #endif
  60. }
  61. HttpCachePolicy policy;
  62. CachedVaryBy varyby;
  63. int status_code;
  64. string status_desc;
  65. int content_length;
  66. NameValueCollection headers;
  67. #if NET_2_0
  68. List <DataItem> data;
  69. #else
  70. ArrayList data;
  71. #endif
  72. IList Data {
  73. get {
  74. if (data == null) {
  75. #if NET_2_0
  76. data = new List <DataItem> ();
  77. #else
  78. data = new ArrayList ();
  79. #endif
  80. }
  81. return data;
  82. }
  83. }
  84. public CachedRawResponse (HttpCachePolicy policy)
  85. {
  86. this.policy = policy;
  87. }
  88. public HttpCachePolicy Policy {
  89. get { return policy; }
  90. set { policy = value; }
  91. }
  92. public CachedVaryBy VaryBy {
  93. get { return varyby; }
  94. set { varyby = value; }
  95. }
  96. public int StatusCode {
  97. get { return status_code; }
  98. set { status_code = value; }
  99. }
  100. public string StatusDescription {
  101. get { return status_desc; }
  102. set { status_desc = value; }
  103. }
  104. public NameValueCollection Headers {
  105. get { return headers; }
  106. }
  107. public void SetHeaders (NameValueCollection headers)
  108. {
  109. this.headers = headers;
  110. }
  111. public void SetData (MemoryStream ms)
  112. {
  113. if (ms == null)
  114. return;
  115. Data.Add (new DataItem (ms.GetBuffer (), ms.Length));
  116. }
  117. #if NET_2_0
  118. public void SetData (HttpResponseSubstitutionCallback callback)
  119. {
  120. if (callback == null)
  121. return;
  122. Data.Add (new DataItem (callback));
  123. }
  124. #endif
  125. public IList GetData ()
  126. {
  127. int count = data != null ? data.Count :0;
  128. if (count == 0)
  129. return null;
  130. return data;
  131. }
  132. }
  133. }