From 7f0bcc5aa1f7afc0d24734978bfd784ae8ac1558 Mon Sep 17 00:00:00 2001 From: Dr Scofield Date: Mon, 7 Jul 2008 09:47:36 +0000 Subject: further progress on HttpServer integration: OSHttpRequest can now be instantiated from both .NET and HttpServer code path. --- OpenSim/Framework/Servers/OSHttpRequest.cs | 64 ++++++++++++++++++-------- OpenSim/Framework/Servers/OSHttpRequestPump.cs | 5 +- OpenSim/Framework/Servers/OSHttpResponse.cs | 4 +- OpenSim/Framework/Servers/OSHttpServer.cs | 18 +++++++- 4 files changed, 65 insertions(+), 26 deletions(-) (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/Servers/OSHttpRequest.cs b/OpenSim/Framework/Servers/OSHttpRequest.cs index 1eb094e..f8f542b 100644 --- a/OpenSim/Framework/Servers/OSHttpRequest.cs +++ b/OpenSim/Framework/Servers/OSHttpRequest.cs @@ -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 q in req.QueryString) + { + _queryString.Add(q.Key, q.Value.Value); + } } } } diff --git a/OpenSim/Framework/Servers/OSHttpRequestPump.cs b/OpenSim/Framework/Servers/OSHttpRequestPump.cs index 78bd1e1..b76fadc 100644 --- a/OpenSim/Framework/Servers/OSHttpRequestPump.cs +++ b/OpenSim/Framework/Servers/OSHttpRequestPump.cs @@ -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; } diff --git a/OpenSim/Framework/Servers/OSHttpResponse.cs b/OpenSim/Framework/Servers/OSHttpResponse.cs index 72be790..e1ab005 100644 --- a/OpenSim/Framework/Servers/OSHttpResponse.cs +++ b/OpenSim/Framework/Servers/OSHttpResponse.cs @@ -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; diff --git a/OpenSim/Framework/Servers/OSHttpServer.cs b/OpenSim/Framework/Servers/OSHttpServer.cs index aade003..4940101 100644 --- a/OpenSim/Framework/Servers/OSHttpServer.cs +++ b/OpenSim/Framework/Servers/OSHttpServer.cs @@ -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); + } + /// /// Engine keeps the HTTP server running. /// 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); } -- cgit v1.1