示例#1
0
        public void HttpRequestHandler(UUID requestID, OSHttpRequest request)
        {
            lock (request)
            {
                string uri = request.RawUrl;

                try
                {
                    int pos1 = uri.IndexOf("/"); // /lslhttp
                    int pos2 = uri.IndexOf("/", pos1 + 1); // /lslhttp/
                    int pos3 = uri.IndexOf("/", pos2 + 1); // /lslhttp/<UUID>/
                    string uri_tmp = uri.Substring(0, pos3 + 1);

                    string pathInfo = uri.Substring(pos3);

                    UrlData url = m_UrlMap[MainServer.Instance.ServerURI + uri_tmp];

                    //for llGetHttpHeader support we need to store original URI here
                    //to make x-path-info / x-query-string / x-script-url / x-remote-ip headers
                    //as per http://wiki.secondlife.com/wiki/LlGetHTTPHeader

                    RequestData requestData = new RequestData
                                                  {
                                                      requestID = requestID,
                                                      requestDone = false,
                                                      startTime = Environment.TickCount,
                                                      uri = uri
                                                  };
                    if (requestData.headers == null)
                        requestData.headers = new Dictionary<string, string>();

                    foreach (string header in request.Headers.Keys)
                        requestData.headers.Add(header, request.Headers[header]);

                    //if this machine is behind DNAT/port forwarding, currently this is being
                    //set to address of port forwarding router
                    requestData.headers["x-remote-ip"] = request.RemoteIPEndPoint.ToString();
                    requestData.headers["x-path-info"] = pathInfo;
                    requestData.headers["x-query-string"] = request.QueryString.ToString();
                    requestData.headers["x-script-url"] = url.url;
                    requestData.contentType = "text/plain";

                    //requestData.ev = new ManualResetEvent(false);
                    lock (url.requests)
                    {
                        url.requests.Add(requestID, requestData);
                    }
                    lock (m_RequestMap)
                    {
                        //add to request map
                        m_RequestMap.Add(requestID, url);
                    }

                    url.engine.PostScriptEvent(url.itemID, url.hostID, "http_request",
                                               new Object[]
                                                   {
                                                       requestID.ToString(), request.HttpMethod,
                                                       HttpServerHandlerHelpers.ReadString(request.InputStream)
                                                   });
                }
                catch (Exception we)
                {
                    //Hashtable response = new Hashtable();
                    MainConsole.Instance.Warn("[HttpRequestHandler]: http-in request failed");
                    MainConsole.Instance.Warn(we.Message);
                    MainConsole.Instance.Warn(we.StackTrace);
                }
            }
        }
示例#2
0
        public void HttpRequestHandler(UUID requestID, Hashtable request)
        {
            lock (request)
            {
                string uri = request["uri"].ToString();
                
                try
                {
                    Hashtable headers = (Hashtable)request["headers"];
                    
                    int pos1 = uri.IndexOf("/");// /lslhttp
                    int pos2 = uri.IndexOf("/", pos1 + 1);// /lslhttp/
                    int pos3 = uri.IndexOf("/", pos2 + 1);// /lslhttp/<UUID>/
                    string uri_tmp = uri.Substring(0, pos3 + 1);
                    //HTTP server code doesn't provide us with QueryStrings
                    string queryString = "";

                    string pathInfo = uri.Substring(pos3);

                    UrlData url = m_UrlMap[m_HttpServer.ServerURI + uri_tmp];

                    //for llGetHttpHeader support we need to store original URI here
                    //to make x-path-info / x-query-string / x-script-url / x-remote-ip headers 
                    //as per http://wiki.secondlife.com/wiki/LlGetHTTPHeader

                    RequestData requestData = new RequestData
                                                  {
                                                      requestID = requestID,
                                                      requestDone = false,
                                                      startTime = Environment.TickCount,
                                                      uri = uri
                                                  };
                    if (requestData.headers == null)
                        requestData.headers = new Dictionary<string, string>();

                    foreach (DictionaryEntry header in headers)
                    {
                        string key = (string)header.Key;
                        string value = (string)header.Value;
                        requestData.headers.Add(key, value);
                    }
                    foreach (DictionaryEntry de in request)
                    {
                        if (de.Key.ToString() == "querystringkeys")
                        {
                            String[] keys = (String[])de.Value;
                            foreach (String key in keys)
                            {
                                if (request.ContainsKey(key))
                                {
                                    string val = (String)request[key];
                                    queryString = queryString + key + "=" + val + "&";
                                }
                            }
                            if (queryString.Length > 1)
                                queryString = queryString.Substring(0, queryString.Length - 1);

                        }

                    }

                    //if this machine is behind DNAT/port forwarding, currently this is being
                    //set to address of port forwarding router
                    requestData.headers["x-remote-ip"] = requestData.headers["remote_addr"];
                    requestData.headers["x-path-info"] = pathInfo;
                    requestData.headers["x-query-string"] = queryString;
                    requestData.headers["x-script-url"] = url.url;

                    //requestData.ev = new ManualResetEvent(false);
                    lock (url.requests)
                    {
                        url.requests.Add(requestID, requestData);
                    }
                    lock (m_RequestMap)
                    {
                        //add to request map
                        m_RequestMap.Add(requestID, url);
                    }

                    url.engine.PostScriptEvent(url.itemID, url.hostID, "http_request", new Object[] { requestID.ToString(), request["http-method"].ToString(), request["body"].ToString() });

                    //send initial response?
//                    Hashtable response = new Hashtable();

                    return;

                }
                catch (Exception we)
                {
                    //Hashtable response = new Hashtable();
                    MainConsole.Instance.Warn("[HttpRequestHandler]: http-in request failed");
                    MainConsole.Instance.Warn(we.Message);
                    MainConsole.Instance.Warn(we.StackTrace);
                }
            }
        }
示例#3
0
        public void HttpRequestHandler(UUID requestID, OSHttpRequest request)
        {
            lock (request)
            {
                string uri = request.RawUrl;

                try
                {
                    int    pos1    = uri.IndexOf("/");           // /lslhttp
                    int    pos2    = uri.IndexOf("/", pos1 + 1); // /lslhttp/
                    int    pos3    = uri.IndexOf("/", pos2 + 1); // /lslhttp/<UUID>/
                    string uri_tmp = uri.Substring(0, pos3 + 1);

                    string pathInfo = uri.Substring(pos3);

                    UrlData url = m_UrlMap[MainServer.Instance.ServerURI + uri_tmp];

                    //for llGetHttpHeader support we need to store original URI here
                    //to make x-path-info / x-query-string / x-script-url / x-remote-ip headers
                    //as per http://wiki.secondlife.com/wiki/LlGetHTTPHeader

                    RequestData requestData = new RequestData
                    {
                        requestID   = requestID,
                        requestDone = false,
                        startTime   = Environment.TickCount,
                        uri         = uri
                    };
                    if (requestData.headers == null)
                    {
                        requestData.headers = new Dictionary <string, string>();
                    }

                    foreach (string header in request.Headers.Keys)
                    {
                        requestData.headers.Add(header, request.Headers[header]);
                    }

                    //if this machine is behind DNAT/port forwarding, currently this is being
                    //set to address of port forwarding router
                    requestData.headers["x-remote-ip"]    = request.RemoteIPEndPoint.ToString();
                    requestData.headers["x-path-info"]    = pathInfo;
                    requestData.headers["x-query-string"] = request.QueryString.ToString();
                    requestData.headers["x-script-url"]   = url.url;
                    requestData.contentType = "text/plain";

                    //requestData.ev = new ManualResetEvent(false);
                    lock (url.requests)
                    {
                        url.requests.Add(requestID, requestData);
                    }
                    lock (m_RequestMap)
                    {
                        //add to request map
                        m_RequestMap.Add(requestID, url);
                    }

                    url.engine.PostScriptEvent(url.itemID, url.hostID, "http_request",
                                               new Object[]
                    {
                        requestID.ToString(), request.HttpMethod,
                        HttpServerHandlerHelpers.ReadString(request.InputStream)
                    });
                }
                catch (Exception we)
                {
                    //Hashtable response = new Hashtable();
                    MainConsole.Instance.Warn("[HttpRequestHandler]: http-in request failed");
                    MainConsole.Instance.Warn(we.Message);
                    MainConsole.Instance.Warn(we.StackTrace);
                }
            }
        }