further progress on HttpServer integration: OSHttpRequest can now be

instantiated from both .NET and HttpServer code path.
0.6.0-stable
Dr Scofield 2008-07-07 09:47:36 +00:00
parent 56c6bdcb26
commit 7f0bcc5aa1
4 changed files with 65 additions and 26 deletions

View File

@ -26,6 +26,7 @@
*/
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Net;
using System.IO;
@ -43,12 +44,12 @@ namespace OpenSim.Framework.Servers
private Encoding _contentEncoding;
private long _contentLength64;
private string _contentType;
private CookieCollection _cookies;
// private CookieCollection _cookies;
private NameValueCollection _headers;
private string _httpMethod;
private Stream _inputStream;
private bool _isSecureConnection;
private bool _isAuthenticated;
// private bool _isSecureConnection;
// private bool _isAuthenticated;
private bool _keepAlive;
private bool _hasbody;
private string _rawUrl;
@ -76,7 +77,7 @@ namespace OpenSim.Framework.Servers
public long ContentLength64
{
get { return _contentLength64; }
get { return ContentLength; }
}
public string ContentType
@ -84,10 +85,11 @@ namespace OpenSim.Framework.Servers
get { return _contentType; }
}
public CookieCollection Cookies
{
get { return _cookies; }
}
// public CookieCollection Cookies
// {
// get { return _cookies; }
// }
public NameValueCollection Headers
{
@ -104,15 +106,15 @@ namespace OpenSim.Framework.Servers
get { return _inputStream; }
}
public bool IsSecureConnection
{
get { return _isSecureConnection; }
}
// public bool IsSecureConnection
// {
// get { return _isSecureConnection; }
// }
public bool IsAuthenticated
{
get { return _isAuthenticated; }
}
// public bool IsAuthenticated
// {
// get { return _isAuthenticated; }
// }
public bool HasEntityBody
{
@ -159,13 +161,13 @@ namespace OpenSim.Framework.Servers
_contentEncoding = req.ContentEncoding;
_contentLength64 = req.ContentLength64;
_contentType = req.ContentType;
_cookies = req.Cookies;
// _cookies = req.Cookies;
_headers = req.Headers;
_httpMethod = req.HttpMethod;
_hasbody = req.HasEntityBody;
_inputStream = req.InputStream;
_isSecureConnection = req.IsSecureConnection;
_isAuthenticated = req.IsAuthenticated;
// _isSecureConnection = req.IsSecureConnection;
// _isAuthenticated = req.IsAuthenticated;
_keepAlive = req.KeepAlive;
_rawUrl = req.RawUrl;
_url = req.Url;
@ -177,6 +179,30 @@ namespace OpenSim.Framework.Servers
{
// _context = context;
_request = req;
_acceptTypes = req.AcceptTypes;
if (null != req.Headers["content-encoding"])
_contentEncoding = Encoding.GetEncoding(_request.Headers["content-encoding"]);
_contentLength64 = req.ContentLength;
if (null != req.Headers["content-type"])
_contentType = _request.Headers["content-type"];
// _cookies = req.Cookies;
_headers = req.Headers;
_httpMethod = req.Method;
_hasbody = req.ContentLength != 0;
_inputStream = req.Body;
// _isSecureConnection = req.IsSecureConnection;
// _isAuthenticated = req.IsAuthenticated;
_keepAlive = ConnectionType.KeepAlive == req.Connection;
_rawUrl = req.Uri.AbsolutePath;
_url = req.Uri;
if (null != req.Headers["user-agent"])
_userAgent = req.Headers["user-agent"];
_queryString = new NameValueCollection();
foreach (KeyValuePair<string, HttpInputItem> q in req.QueryString)
{
_queryString.Add(q.Key, q.Value.Value);
}
}
}
}

View File

@ -133,9 +133,8 @@ namespace OpenSim.Framework.Servers
throw new Exception(String.Format("[{0}] got unexpected OSHttpHandlerResult {1}", EngineID, rc));
}
// Handled: clean up
// response.KeepAlive = false;
// response.SendChunked = false;
// Handled: clean up now
req.HttpRequest.AddHeader("keep-alive", "false");
break;
}

View File

@ -73,7 +73,7 @@ namespace OpenSim.Framework.Servers
}
public WebHeaderCollection Headers;
public CookieCollection Cookies;
// public CookieCollection Cookies;
private bool _keepAlive;
public bool KeepAlive
@ -144,7 +144,7 @@ namespace OpenSim.Framework.Servers
ContentLength64 = resp.ContentLength64;
_contentType = resp.ContentType;
Headers = resp.Headers;
Cookies = resp.Cookies;
// Cookies = resp.Cookies;
KeepAlive = resp.KeepAlive;
OutputStream = resp.OutputStream;
RedirectLocation = resp.RedirectLocation;

View File

@ -50,6 +50,8 @@ namespace OpenSim.Framework.Servers
{
private static readonly ILog _log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private object _syncObject = new object();
// underlying HttpServer.HttpListener
protected HttpListener _listener;
// underlying core/engine thread
@ -157,16 +159,28 @@ namespace OpenSim.Framework.Servers
_pumps[i].Start();
}
public void Stop()
{
lock (_syncObject) Monitor.Pulse(_syncObject);
}
/// <summary>
/// Engine keeps the HTTP server running.
/// </summary>
private void Engine()
{
while (true)
{
try {
_listener.RequestHandler += OnHttpRequest;
_listener.Start(QueueSize);
_log.InfoFormat("[{0}] HTTP server started", EngineID);
lock (_syncObject) Monitor.Wait(_syncObject);
}
catch (Exception)
{
}
_log.InfoFormat("[{0}] HTTP server terminated", EngineID);
}