aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Servers/Tests/OSHttpTests.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/Servers/Tests/OSHttpTests.cs')
-rw-r--r--OpenSim/Framework/Servers/Tests/OSHttpTests.cs324
1 files changed, 322 insertions, 2 deletions
diff --git a/OpenSim/Framework/Servers/Tests/OSHttpTests.cs b/OpenSim/Framework/Servers/Tests/OSHttpTests.cs
index 5c0e0df..1b47cc6 100644
--- a/OpenSim/Framework/Servers/Tests/OSHttpTests.cs
+++ b/OpenSim/Framework/Servers/Tests/OSHttpTests.cs
@@ -41,7 +41,327 @@ namespace OpenSim.Framework.Servers.Tests
41{ 41{
42 [TestFixture] 42 [TestFixture]
43 public class OSHttpTests : OpenSimTestCase 43 public class OSHttpTests : OpenSimTestCase
44 { 44 {
45 // we need an IHttpClientContext for our tests
46 public class TestHttpClientContext: IHttpClientContext
47 {
48 private bool _secured;
49 public bool IsSecured
50 {
51 get { return _secured; }
52 }
53 public bool Secured
54 {
55 get { return _secured; }
56 }
57
58 public TestHttpClientContext(bool secured)
59 {
60 _secured = secured;
61 }
62
63 public void Disconnect(SocketError error) {}
64 public void Respond(string httpVersion, HttpStatusCode statusCode, string reason, string body) {}
65 public void Respond(string httpVersion, HttpStatusCode statusCode, string reason) {}
66 public void Respond(string body) {}
67 public void Send(byte[] buffer) {}
68 public void Send(byte[] buffer, int offset, int size) {}
69 public void Respond(string httpVersion, HttpStatusCode statusCode, string reason, string body, string contentType) {}
70 public void Close() { }
71 public bool EndWhenDone { get { return false;} set { return;}}
72
73 public HTTPNetworkContext GiveMeTheNetworkStreamIKnowWhatImDoing()
74 {
75 return new HTTPNetworkContext();
76 }
77
78 public event EventHandler<DisconnectedEventArgs> Disconnected = delegate { };
79 /// <summary>
80 /// A request have been received in the context.
81 /// </summary>
82 public event EventHandler<RequestEventArgs> RequestReceived = delegate { };
83
84 public bool CanSend { get { return true; } }
85 public string RemoteEndPoint { get { return ""; } }
86 public string RemoteEndPointAddress { get { return ""; } }
87 public string RemoteEndPointPort { get { return ""; } }
88 }
89
90 public class TestHttpRequest: IHttpRequest
91 {
92 private string _uriPath;
93 public bool BodyIsComplete
94 {
95 get { return true; }
96 }
97 public string[] AcceptTypes
98 {
99 get {return _acceptTypes; }
100 }
101 private string[] _acceptTypes;
102 public Stream Body
103 {
104 get { return _body; }
105 set { _body = value;}
106 }
107 private Stream _body;
108 public ConnectionType Connection
109 {
110 get { return _connection; }
111 set { _connection = value; }
112 }
113 private ConnectionType _connection;
114 public int ContentLength
115 {
116 get { return _contentLength; }
117 set { _contentLength = value; }
118 }
119 private int _contentLength;
120 public NameValueCollection Headers
121 {
122 get { return _headers; }
123 }
124 private NameValueCollection _headers = new NameValueCollection();
125 public string HttpVersion
126 {
127 get { return _httpVersion; }
128 set { _httpVersion = value; }
129 }
130 private string _httpVersion = null;
131 public string Method
132 {
133 get { return _method; }
134 set { _method = value; }
135 }
136 private string _method = null;
137 public HttpInput QueryString
138 {
139 get { return _queryString; }
140 }
141 private HttpInput _queryString = null;
142 public Uri Uri
143 {
144 get { return _uri; }
145 set { _uri = value; }
146 }
147 private Uri _uri = null;
148 public string[] UriParts
149 {
150 get { return _uri.Segments; }
151 }
152 public HttpParam Param
153 {
154 get { return null; }
155 }
156 public HttpForm Form
157 {
158 get { return null; }
159 }
160 public bool IsAjax
161 {
162 get { return false; }
163 }
164 public RequestCookies Cookies
165 {
166 get { return null; }
167 }
168
169 public TestHttpRequest() {}
170
171 public TestHttpRequest(string contentEncoding, string contentType, string userAgent,
172 string remoteAddr, string remotePort, string[] acceptTypes,
173 ConnectionType connectionType, int contentLength, Uri uri)
174 {
175 _headers["content-encoding"] = contentEncoding;
176 _headers["content-type"] = contentType;
177 _headers["user-agent"] = userAgent;
178 _headers["remote_addr"] = remoteAddr;
179 _headers["remote_port"] = remotePort;
180
181 _acceptTypes = acceptTypes;
182 _connection = connectionType;
183 _contentLength = contentLength;
184 _uri = uri;
185 }
186
187 public void DecodeBody(FormDecoderProvider providers) {}
188 public void SetCookies(RequestCookies cookies) {}
189 public void AddHeader(string name, string value)
190 {
191 _headers.Add(name, value);
192 }
193 public int AddToBody(byte[] bytes, int offset, int length)
194 {
195 return 0;
196 }
197 public void Clear() {}
198
199 public object Clone()
200 {
201 TestHttpRequest clone = new TestHttpRequest();
202 clone._acceptTypes = _acceptTypes;
203 clone._connection = _connection;
204 clone._contentLength = _contentLength;
205 clone._uri = _uri;
206 clone._headers = new NameValueCollection(_headers);
207
208 return clone;
209 }
210 public IHttpResponse CreateResponse(IHttpClientContext context)
211 {
212 return new HttpResponse(context, this);
213 }
214 /// <summary>
215 /// Path and query (will be merged with the host header) and put in Uri
216 /// </summary>
217 /// <see cref="Uri"/>
218 public string UriPath
219 {
220 get { return _uriPath; }
221 set
222 {
223 _uriPath = value;
224
225 }
226 }
227
228 }
229
230 public class TestHttpResponse: IHttpResponse
231 {
232 public Stream Body
233 {
234 get { return _body; }
235
236 set { _body = value; }
237 }
238 private Stream _body;
239
240 public string ProtocolVersion
241 {
242 get { return _protocolVersion; }
243 set { _protocolVersion = value; }
244 }
245 private string _protocolVersion;
246
247 public bool Chunked
248 {
249 get { return _chunked; }
250
251 set { _chunked = value; }
252 }
253 private bool _chunked;
254
255 public ConnectionType Connection
256 {
257 get { return _connection; }
258
259 set { _connection = value; }
260 }
261 private ConnectionType _connection;
262
263 public Encoding Encoding
264 {
265 get { return _encoding; }
266
267 set { _encoding = value; }
268 }
269 private Encoding _encoding;
270
271 public int KeepAlive
272 {
273 get { return _keepAlive; }
274
275 set { _keepAlive = value; }
276 }
277 private int _keepAlive;
278
279 public HttpStatusCode Status
280 {
281 get { return _status; }
282
283 set { _status = value; }
284 }
285 private HttpStatusCode _status;
286
287 public string Reason
288 {
289 get { return _reason; }
290
291 set { _reason = value; }
292 }
293 private string _reason;
294
295 public long ContentLength
296 {
297 get { return _contentLength; }
298
299 set { _contentLength = value; }
300 }
301 private long _contentLength;
302
303 public string ContentType
304 {
305 get { return _contentType; }
306
307 set { _contentType = value; }
308 }
309 private string _contentType;
310
311 public bool HeadersSent
312 {
313 get { return _headersSent; }
314 }
315 private bool _headersSent;
316
317 public bool Sent
318 {
319 get { return _sent; }
320 }
321 private bool _sent;
322
323 public ResponseCookies Cookies
324 {
325 get { return _cookies; }
326 }
327 private ResponseCookies _cookies = null;
328
329 public TestHttpResponse()
330 {
331 _headersSent = false;
332 _sent = false;
333 }
334
335 public void AddHeader(string name, string value) {}
336 public void Send()
337 {
338 if (!_headersSent) SendHeaders();
339 if (_sent) throw new InvalidOperationException("stuff already sent");
340 _sent = true;
341 }
342
343 public void SendBody(byte[] buffer, int offset, int count)
344 {
345 if (!_headersSent) SendHeaders();
346 _sent = true;
347 }
348 public void SendBody(byte[] buffer)
349 {
350 if (!_headersSent) SendHeaders();
351 _sent = true;
352 }
353
354 public void SendHeaders()
355 {
356 if (_headersSent) throw new InvalidOperationException("headers already sent");
357 _headersSent = true;
358 }
359
360 public void Redirect(Uri uri) {}
361 public void Redirect(string url) {}
362 }
363
364
45 public OSHttpRequest req0; 365 public OSHttpRequest req0;
46 public OSHttpRequest req1; 366 public OSHttpRequest req1;
47 367
@@ -113,4 +433,4 @@ namespace OpenSim.Framework.Servers.Tests
113 Assert.That(rsp0.ContentType, Is.EqualTo("text/xml")); 433 Assert.That(rsp0.ContentType, Is.EqualTo("text/xml"));
114 } 434 }
115 } 435 }
116} \ No newline at end of file 436}