TestHttpRequest.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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.Collections.Specialized;
  29. using System.IO;
  30. using HttpServer;
  31. using HttpServer.FormDecoders;
  32. namespace OpenSim.Tests.Common
  33. {
  34. /*
  35. public class TestHttpRequest: IHttpRequest
  36. {
  37. private string _uriPath;
  38. public bool BodyIsComplete
  39. {
  40. get { return true; }
  41. }
  42. public string[] AcceptTypes
  43. {
  44. get {return _acceptTypes; }
  45. }
  46. private string[] _acceptTypes;
  47. public Stream Body
  48. {
  49. get { return _body; }
  50. set { _body = value;}
  51. }
  52. private Stream _body;
  53. public ConnectionType Connection
  54. {
  55. get { return _connection; }
  56. set { _connection = value; }
  57. }
  58. private ConnectionType _connection;
  59. public int ContentLength
  60. {
  61. get { return _contentLength; }
  62. set { _contentLength = value; }
  63. }
  64. private int _contentLength;
  65. public NameValueCollection Headers
  66. {
  67. get { return _headers; }
  68. }
  69. private NameValueCollection _headers = new NameValueCollection();
  70. public string HttpVersion { get; set; }
  71. public string Method
  72. {
  73. get { return _method; }
  74. set { _method = value; }
  75. }
  76. private string _method = null;
  77. public HttpInput QueryString
  78. {
  79. get { return _queryString; }
  80. }
  81. private HttpInput _queryString = null;
  82. public Uri Uri
  83. {
  84. get { return _uri; }
  85. set { _uri = value; }
  86. }
  87. private Uri _uri = null;
  88. public string[] UriParts
  89. {
  90. get { return _uri.Segments; }
  91. }
  92. public HttpParam Param
  93. {
  94. get { return null; }
  95. }
  96. public HttpForm Form
  97. {
  98. get { return null; }
  99. }
  100. public bool IsAjax
  101. {
  102. get { return false; }
  103. }
  104. public RequestCookies Cookies
  105. {
  106. get { return null; }
  107. }
  108. public TestHttpRequest()
  109. {
  110. HttpVersion = "HTTP/1.1";
  111. }
  112. public TestHttpRequest(string contentEncoding, string contentType, string userAgent,
  113. string remoteAddr, string remotePort, string[] acceptTypes,
  114. ConnectionType connectionType, int contentLength, Uri uri) : base()
  115. {
  116. _headers["content-encoding"] = contentEncoding;
  117. _headers["content-type"] = contentType;
  118. _headers["user-agent"] = userAgent;
  119. _headers["remote_addr"] = remoteAddr;
  120. _headers["remote_port"] = remotePort;
  121. _acceptTypes = acceptTypes;
  122. _connection = connectionType;
  123. _contentLength = contentLength;
  124. _uri = uri;
  125. }
  126. public void DecodeBody(FormDecoderProvider providers) {}
  127. public void SetCookies(RequestCookies cookies) {}
  128. public void AddHeader(string name, string value)
  129. {
  130. _headers.Add(name, value);
  131. }
  132. public int AddToBody(byte[] bytes, int offset, int length)
  133. {
  134. return 0;
  135. }
  136. public void Clear() {}
  137. public object Clone()
  138. {
  139. TestHttpRequest clone = new TestHttpRequest();
  140. clone._acceptTypes = _acceptTypes;
  141. clone._connection = _connection;
  142. clone._contentLength = _contentLength;
  143. clone._uri = _uri;
  144. clone._headers = new NameValueCollection(_headers);
  145. return clone;
  146. }
  147. public IHttpResponse CreateResponse(IHttpClientContext context)
  148. {
  149. return new HttpResponse(context, this);
  150. }
  151. /// <summary>
  152. /// Path and query (will be merged with the host header) and put in Uri
  153. /// </summary>
  154. /// <see cref="Uri"/>
  155. public string UriPath
  156. {
  157. get { return _uriPath; }
  158. set
  159. {
  160. _uriPath = value;
  161. }
  162. }
  163. }
  164. */
  165. }