CachedRawResponse.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. int content_length;
  60. NameValueCollection headers;
  61. List <DataItem> data;
  62. IList Data {
  63. get {
  64. if (data == null)
  65. data = new List <DataItem> ();
  66. return data;
  67. }
  68. }
  69. public CachedRawResponse (HttpCachePolicy policy)
  70. {
  71. this.policy = policy;
  72. }
  73. public HttpCachePolicy Policy {
  74. get { return policy; }
  75. set { policy = value; }
  76. }
  77. public CachedVaryBy VaryBy {
  78. get { return varyby; }
  79. set { varyby = value; }
  80. }
  81. public int StatusCode {
  82. get { return status_code; }
  83. set { status_code = value; }
  84. }
  85. public string StatusDescription {
  86. get { return status_desc; }
  87. set { status_desc = value; }
  88. }
  89. public NameValueCollection Headers {
  90. get { return headers; }
  91. }
  92. public void SetHeaders (NameValueCollection headers)
  93. {
  94. this.headers = headers;
  95. }
  96. public void SetData (MemoryStream ms)
  97. {
  98. if (ms == null)
  99. return;
  100. Data.Add (new DataItem (ms.GetBuffer (), ms.Length));
  101. }
  102. public void SetData (HttpResponseSubstitutionCallback callback)
  103. {
  104. if (callback == null)
  105. return;
  106. Data.Add (new DataItem (callback));
  107. }
  108. public IList GetData ()
  109. {
  110. int count = data != null ? data.Count :0;
  111. if (count == 0)
  112. return null;
  113. return data;
  114. }
  115. }
  116. }