OSHttpResponse.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSim Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System.Collections;
  28. using System.IO;
  29. using System.Net;
  30. using System.Text;
  31. namespace OpenSim.Framework.Servers
  32. {
  33. public class OSHttpResponse
  34. {
  35. private string _contentType;
  36. private bool _contentTypeSet;
  37. public string ContentType
  38. {
  39. get { return _contentType; }
  40. set
  41. {
  42. _contentType = value;
  43. _contentTypeSet = true;
  44. }
  45. }
  46. public bool IsContentTypeSet
  47. {
  48. get { return _contentTypeSet; }
  49. }
  50. private long _contentLength64;
  51. public long ContentLength64
  52. {
  53. get { return _contentLength64; }
  54. set
  55. {
  56. _contentLength64 = value;
  57. if (null != _resp) _resp.ContentLength64 = value;
  58. }
  59. }
  60. private Encoding _contentEncoding;
  61. public Encoding ContentEncoding
  62. {
  63. get { return _contentEncoding; }
  64. set
  65. {
  66. _contentEncoding = value;
  67. if (null != _resp) _resp.ContentEncoding = value;
  68. }
  69. }
  70. public WebHeaderCollection Headers;
  71. public CookieCollection Cookies;
  72. private bool _keepAlive;
  73. public bool KeepAlive
  74. {
  75. get { return _keepAlive; }
  76. set
  77. {
  78. _keepAlive = value;
  79. if (null != _resp) _resp.KeepAlive = value;
  80. }
  81. }
  82. public Stream OutputStream;
  83. private string _redirectLocation;
  84. public string RedirectLocation
  85. {
  86. get { return _redirectLocation; }
  87. set
  88. {
  89. _redirectLocation = value;
  90. if (null != _resp) _resp.RedirectLocation = value;
  91. }
  92. }
  93. private bool _sendChunked;
  94. public bool SendChunked
  95. {
  96. get { return _sendChunked; }
  97. set
  98. {
  99. _sendChunked = value;
  100. if (null != _resp) _resp.SendChunked = value;
  101. }
  102. }
  103. private int _statusCode;
  104. public int StatusCode
  105. {
  106. get { return _statusCode; }
  107. set
  108. {
  109. _statusCode = value;
  110. if (null != _resp) _resp.StatusCode = value;
  111. }
  112. }
  113. private string _statusDescription;
  114. public string StatusDescription
  115. {
  116. get { return _statusDescription; }
  117. set
  118. {
  119. _statusDescription = value;
  120. if (null != _resp) _resp.StatusDescription = value;
  121. }
  122. }
  123. private HttpListenerResponse _resp;
  124. public OSHttpResponse()
  125. {
  126. }
  127. public OSHttpResponse(HttpListenerResponse resp)
  128. {
  129. ContentEncoding = resp.ContentEncoding;
  130. ContentLength64 = resp.ContentLength64;
  131. _contentType = resp.ContentType;
  132. Headers = resp.Headers;
  133. Cookies = resp.Cookies;
  134. KeepAlive = resp.KeepAlive;
  135. OutputStream = resp.OutputStream;
  136. RedirectLocation = resp.RedirectLocation;
  137. SendChunked = resp.SendChunked;
  138. StatusCode = resp.StatusCode;
  139. StatusDescription = resp.StatusDescription;
  140. _contentTypeSet = false;
  141. _resp = resp;
  142. }
  143. public void AddHeader(string key, string value)
  144. {
  145. Headers.Add(key, value);
  146. }
  147. }
  148. }