29 using System.Collections.Specialized;
32 using System.Net.Sockets;
35 using HttpServer.FormDecoders;
36 using NUnit.Framework;
37 using OpenSim.Framework.Servers.HttpServer;
38 using OpenSim.Tests.Common;
48 private bool _secured;
51 get {
return _secured; }
55 get {
return _secured; }
64 public void Respond(
string httpVersion, HttpStatusCode statusCode,
string reason,
string body) {}
65 public void Respond(
string httpVersion, HttpStatusCode statusCode,
string reason) {}
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) {}
71 public bool EndWhenDone {
get {
return false;} set {
return;}}
75 return new HTTPNetworkContext();
78 public event EventHandler<DisconnectedEventArgs> Disconnected = delegate { };
82 public event EventHandler<RequestEventArgs> RequestReceived = delegate { };
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 ""; } }
92 private string _uriPath;
93 public bool BodyIsComplete
97 public string[] AcceptTypes
99 get {
return _acceptTypes; }
101 private string[] _acceptTypes;
104 get {
return _body; }
105 set { _body = value;}
107 private Stream _body;
108 public ConnectionType Connection
110 get {
return _connection; }
111 set { _connection = value; }
113 private ConnectionType _connection;
114 public int ContentLength
116 get {
return _contentLength; }
117 set { _contentLength = value; }
119 private int _contentLength;
120 public NameValueCollection Headers
122 get {
return _headers; }
124 private NameValueCollection _headers =
new NameValueCollection();
125 public string HttpVersion
127 get {
return _httpVersion; }
128 set { _httpVersion = value; }
130 private string _httpVersion = null;
133 get {
return _method; }
134 set { _method = value; }
136 private string _method = null;
137 public HttpInput QueryString
139 get {
return _queryString; }
141 private HttpInput _queryString = null;
145 set { _uri = value; }
147 private Uri _uri = null;
148 public string[] UriParts
150 get {
return _uri.Segments; }
152 public HttpParam Param
162 get {
return false; }
164 public RequestCookies Cookies
172 string remoteAddr,
string remotePort,
string[] acceptTypes,
173 ConnectionType connectionType,
int contentLength, Uri uri)
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;
181 _acceptTypes = acceptTypes;
182 _connection = connectionType;
183 _contentLength = contentLength;
191 _headers.Add(name, value);
193 public int AddToBody(byte[] bytes,
int offset,
int length)
202 clone._acceptTypes = _acceptTypes;
203 clone._connection = _connection;
204 clone._contentLength = _contentLength;
206 clone._headers =
new NameValueCollection(_headers);
212 return new HttpResponse(context,
this);
218 public string UriPath
220 get {
return _uriPath; }
234 get {
return _body; }
236 set { _body = value; }
238 private Stream _body;
240 public string ProtocolVersion
242 get {
return _protocolVersion; }
243 set { _protocolVersion = value; }
245 private string _protocolVersion;
249 get {
return _chunked; }
251 set { _chunked = value; }
253 private bool _chunked;
255 public ConnectionType Connection
257 get {
return _connection; }
259 set { _connection = value; }
261 private ConnectionType _connection;
263 public Encoding Encoding
265 get {
return _encoding; }
267 set { _encoding = value; }
269 private Encoding _encoding;
273 get {
return _keepAlive; }
275 set { _keepAlive = value; }
277 private int _keepAlive;
279 public HttpStatusCode Status
281 get {
return _status; }
283 set { _status = value; }
285 private HttpStatusCode _status;
289 get {
return _reason; }
291 set { _reason = value; }
293 private string _reason;
295 public long ContentLength
297 get {
return _contentLength; }
299 set { _contentLength = value; }
301 private long _contentLength;
303 public string ContentType
305 get {
return _contentType; }
307 set { _contentType = value; }
309 private string _contentType;
311 public bool HeadersSent
313 get {
return _headersSent; }
315 private bool _headersSent;
319 get {
return _sent; }
323 public ResponseCookies Cookies
325 get {
return _cookies; }
327 private ResponseCookies _cookies = null;
331 _headersSent =
false;
338 if (!_headersSent) SendHeaders();
339 if (_sent)
throw new InvalidOperationException(
"stuff already sent");
343 public void SendBody(byte[] buffer,
int offset,
int count)
345 if (!_headersSent) SendHeaders();
350 if (!_headersSent) SendHeaders();
356 if (_headersSent)
throw new InvalidOperationException(
"headers already sent");
376 new string[] {
"text/xml"},
377 ConnectionType.KeepAlive, 4711,
378 new Uri(
"http://127.0.0.1/admin/inventory/Dr+Who/Tardis"));
379 threq0.Method =
"GET";
380 threq0.HttpVersion = HttpHelper.HTTP10;
383 new string[] {
"text/xml"},
384 ConnectionType.KeepAlive, 4711,
385 new Uri(
"http://127.0.0.1/admin/inventory/Dr+Who/Tardis?a=0&b=1&c=2"));
386 threq1.Method =
"POST";
387 threq1.HttpVersion = HttpHelper.HTTP11;
388 threq1.Headers[
"x-wuff"] =
"wuffwuff";
389 threq1.Headers[
"www-authenticate"] =
"go away";
396 ipEP0 =
new IPEndPoint(IPAddress.Parse(
"192.168.0.1"), 4711);
403 Assert.That(req0.HttpMethod, Is.EqualTo(
"GET"));
404 Assert.That(req0.ContentType, Is.EqualTo(
"text/xml"));
405 Assert.That(req0.ContentLength, Is.EqualTo(4711));
407 Assert.That(req1.HttpMethod, Is.EqualTo(
"POST"));
413 Assert.That(req1.Headers[
"x-wuff"], Is.EqualTo(
"wuffwuff"));
414 Assert.That(req1.Headers.Get(
"x-wuff"), Is.EqualTo(
"wuffwuff"));
416 Assert.That(req1.Headers[
"www-authenticate"], Is.EqualTo(
"go away"));
417 Assert.That(req1.Headers.Get(
"www-authenticate"), Is.EqualTo(
"go away"));
419 Assert.That(req0.RemoteIPEndPoint, Is.EqualTo(ipEP0));
425 Assert.That(req0.RawUrl, Is.EqualTo(
"/admin/inventory/Dr+Who/Tardis"));
426 Assert.That(req1.Url.ToString(), Is.EqualTo(
"http://127.0.0.1/admin/inventory/Dr+Who/Tardis?a=0&b=1&c=2"));
432 rsp0.ContentType =
"text/xml";
433 Assert.That(rsp0.ContentType, Is.EqualTo(
"text/xml"));
void Disconnect(SocketError error)
void Respond(string httpVersion, HttpStatusCode statusCode, string reason, string body)
void AddHeader(string name, string value)
void Redirect(string url)
void AddHeader(string name, string value)
OSHttpResponse is the OpenSim representation of an HTTP response.
void T100_OSHttpResponse()
void Respond(string httpVersion, HttpStatusCode statusCode, string reason, string body, string contentType)
void T002_OSHttpRequestUriParsing()
HTTPNetworkContext GiveMeTheNetworkStreamIKnowWhatImDoing()
void SendBody(byte[] buffer, int offset, int count)
void SetCookies(RequestCookies cookies)
void SendBody(byte[] buffer)
void Respond(string httpVersion, HttpStatusCode statusCode, string reason)
IHttpResponse CreateResponse(IHttpClientContext context)
TestHttpClientContext(bool secured)
Interactive OpenSim region server
int AddToBody(byte[] bytes, int offset, int length)
void Send(byte[] buffer, int offset, int size)
void DecodeBody(FormDecoderProvider providers)
void T000_OSHttpRequest()
void T001_OSHttpRequestHeaderAccess()
TestHttpRequest(string contentEncoding, string contentType, string userAgent, string remoteAddr, string remotePort, string[] acceptTypes, ConnectionType connectionType, int contentLength, Uri uri)
void Respond(string body)