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