From 85b280385fd7400da8bc721131d25eee9fd7f8da Mon Sep 17 00:00:00 2001 From: Teravus Ovares Date: Sat, 27 Sep 2008 09:42:31 +0000 Subject: * This is the very very early beginnings of an EventQueue:get module. * This won't function yet as far as the client can tell.. because it doesn't respond to the first query with a 200 message. * We have to figure out how to encode those binary values in the example code in the module... * Committing this so we have a start point. Will continue to work on this more today. --- OpenSim/Framework/Servers/BaseHTTPHandler.cs | 42 +++++++++++++++++++ OpenSim/Framework/Servers/BaseHttpServer.cs | 61 +++++++++++++++++++++++++--- OpenSim/Framework/Servers/RestHTTPHandler.cs | 57 ++++++++++++++++++++++++++ 3 files changed, 155 insertions(+), 5 deletions(-) create mode 100644 OpenSim/Framework/Servers/BaseHTTPHandler.cs create mode 100644 OpenSim/Framework/Servers/RestHTTPHandler.cs (limited to 'OpenSim/Framework/Servers') diff --git a/OpenSim/Framework/Servers/BaseHTTPHandler.cs b/OpenSim/Framework/Servers/BaseHTTPHandler.cs new file mode 100644 index 0000000..a7c3562 --- /dev/null +++ b/OpenSim/Framework/Servers/BaseHTTPHandler.cs @@ -0,0 +1,42 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSim Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections; + +namespace OpenSim.Framework.Servers +{ + public abstract class BaseHTTPHandler : BaseRequestHandler, IGenericHTTPHandler + { + public abstract Hashtable Handle(string path, Hashtable Request); + + protected BaseHTTPHandler(string httpMethod, string path) + : base(httpMethod, path) + { + } + } +} \ No newline at end of file diff --git a/OpenSim/Framework/Servers/BaseHttpServer.cs b/OpenSim/Framework/Servers/BaseHttpServer.cs index ae07895..24bba2b 100644 --- a/OpenSim/Framework/Servers/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/BaseHttpServer.cs @@ -361,9 +361,57 @@ namespace OpenSim.Framework.Servers buffer = streamedRequestHandler.Handle(path, request.InputStream, request, response); } + else if (requestHandler is IGenericHTTPHandler) + { + IGenericHTTPHandler HTTPRequestHandler = requestHandler as IGenericHTTPHandler; + Stream requestStream = request.InputStream; + + Encoding encoding = Encoding.UTF8; + StreamReader reader = new StreamReader(requestStream, encoding); + + string requestBody = reader.ReadToEnd(); + + + reader.Close(); + requestStream.Close(); + + Hashtable keysvals = new Hashtable(); + Hashtable headervals = new Hashtable(); + string host = String.Empty; + + string[] querystringkeys = request.QueryString.AllKeys; + string[] rHeaders = request.Headers.AllKeys; + + + foreach (string queryname in querystringkeys) + { + keysvals.Add(queryname, request.QueryString[queryname]); + } + + foreach (string headername in rHeaders) + { + //m_log.Warn("[HEADER]: " + headername + "=" + request.Headers[headername]); + headervals[headername] = request.Headers[headername]; + } + + if (headervals.Contains("Host")) + { + host = (string)headervals["Host"]; + } + keysvals.Add("requestbody",requestBody); + if (keysvals.Contains("method")) + { + //m_log.Warn("[HTTP]: Contains Method"); + string method = (string)keysvals["method"]; + //m_log.Warn("[HTTP]: " + requestBody); + + } + DoHTTPGruntWork(HTTPRequestHandler.Handle(path,keysvals), response); + return; + } else { - IStreamHandler streamHandler = (IStreamHandler) requestHandler; + IStreamHandler streamHandler = (IStreamHandler)requestHandler; using (MemoryStream memoryStream = new MemoryStream()) { @@ -943,6 +991,9 @@ namespace OpenSim.Framework.Servers string responseString = (string)responsedata["str_response_string"]; string contentType = (string)responsedata["content_type"]; + if (responsedata.ContainsKey("keepalive")) + response.KeepAlive = true; + //Even though only one other part of the entire code uses HTTPHandlers, we shouldn't expect this //and should check for NullReferenceExceptions @@ -951,10 +1002,9 @@ namespace OpenSim.Framework.Servers contentType = "text/html"; } - // We're forgoing the usual error status codes here because the client - // ignores anything but 200 and 301 - - response.StatusCode = (int)OSHttpStatusCode.SuccessOk; + // The client ignores anything but 200 here for web login, so ensure that this is 200 for that + + response.StatusCode = responsecode; if (responsecode == (int)OSHttpStatusCode.RedirectMovedPermanently) { @@ -978,6 +1028,7 @@ namespace OpenSim.Framework.Servers response.SendChunked = false; response.ContentLength64 = buffer.Length; response.ContentEncoding = Encoding.UTF8; + try { diff --git a/OpenSim/Framework/Servers/RestHTTPHandler.cs b/OpenSim/Framework/Servers/RestHTTPHandler.cs new file mode 100644 index 0000000..2974c56 --- /dev/null +++ b/OpenSim/Framework/Servers/RestHTTPHandler.cs @@ -0,0 +1,57 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSim Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections; + +namespace OpenSim.Framework.Servers +{ + public class RestHTTPHandler : BaseHTTPHandler + { + private GenericHTTPMethod m_dhttpMethod; + + public GenericHTTPMethod Method + { + get { return m_dhttpMethod; } + } + + public override Hashtable Handle(string path, Hashtable request) + { + + string param = GetParam(path); + request.Add("param", param); + request.Add("path", path); + return m_dhttpMethod(request); + } + + public RestHTTPHandler(string httpMethod, string path, GenericHTTPMethod dhttpMethod) + : base(httpMethod, path) + { + m_dhttpMethod = dhttpMethod; + } + } +} -- cgit v1.1