1
0

TestHttpResponse.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 OpenSimulator 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;
  28. using System.IO;
  29. using System.Net;
  30. using System.Text;
  31. using HttpServer;
  32. namespace OpenSim.Tests.Common
  33. {
  34. public class TestHttpResponse: IHttpResponse
  35. {
  36. public Stream Body
  37. {
  38. get { return _body; }
  39. set { _body = value; }
  40. }
  41. private Stream _body;
  42. public string ProtocolVersion
  43. {
  44. get { return _protocolVersion; }
  45. set { _protocolVersion = value; }
  46. }
  47. private string _protocolVersion;
  48. public bool Chunked
  49. {
  50. get { return _chunked; }
  51. set { _chunked = value; }
  52. }
  53. private bool _chunked;
  54. public ConnectionType Connection
  55. {
  56. get { return _connection; }
  57. set { _connection = value; }
  58. }
  59. private ConnectionType _connection;
  60. public Encoding Encoding
  61. {
  62. get { return _encoding; }
  63. set { _encoding = value; }
  64. }
  65. private Encoding _encoding;
  66. public int KeepAlive
  67. {
  68. get { return _keepAlive; }
  69. set { _keepAlive = value; }
  70. }
  71. private int _keepAlive;
  72. public HttpStatusCode Status
  73. {
  74. get { return _status; }
  75. set { _status = value; }
  76. }
  77. private HttpStatusCode _status;
  78. public string Reason
  79. {
  80. get { return _reason; }
  81. set { _reason = value; }
  82. }
  83. private string _reason;
  84. public long ContentLength
  85. {
  86. get { return _contentLength; }
  87. set { _contentLength = value; }
  88. }
  89. private long _contentLength;
  90. public string ContentType
  91. {
  92. get { return _contentType; }
  93. set { _contentType = value; }
  94. }
  95. private string _contentType;
  96. public bool HeadersSent
  97. {
  98. get { return _headersSent; }
  99. }
  100. private bool _headersSent;
  101. public bool Sent
  102. {
  103. get { return _sent; }
  104. }
  105. private bool _sent;
  106. public ResponseCookies Cookies
  107. {
  108. get { return _cookies; }
  109. }
  110. private ResponseCookies _cookies = null;
  111. public TestHttpResponse()
  112. {
  113. _headersSent = false;
  114. _sent = false;
  115. }
  116. public void AddHeader(string name, string value) {}
  117. public void Send()
  118. {
  119. if (!_headersSent) SendHeaders();
  120. if (_sent) throw new InvalidOperationException("stuff already sent");
  121. _sent = true;
  122. }
  123. public void SendBody(byte[] buffer, int offset, int count)
  124. {
  125. if (!_headersSent) SendHeaders();
  126. _sent = true;
  127. }
  128. public void SendBody(byte[] buffer)
  129. {
  130. if (!_headersSent) SendHeaders();
  131. _sent = true;
  132. }
  133. public void SendHeaders()
  134. {
  135. if (_headersSent) throw new InvalidOperationException("headers already sent");
  136. _headersSent = true;
  137. }
  138. public void Redirect(Uri uri) {}
  139. public void Redirect(string url) {}
  140. }
  141. }