Esempio n. 1
0
        public UUID StartHttpRequest(UUID primID, UUID itemID, string url, List <string> parameters,
                                     Dictionary <string, string> headers, string body)
        {
            UUID             reqID = UUID.Random();
            HttpRequestClass htc   = new HttpRequestClass();

            // Partial implementation: support for parameter flags needed
            //   see http://wiki.secondlife.com/wiki/LlHTTPRequest
            //
            // Parameters are expected in {key, value, ... , key, value}

            int BODY_MAXLENGTH = DEFAULT_BODY_MAXLENGTH;

            if (parameters != null)
            {
                string[] parms = parameters.ToArray();
                for (int i = 0; i < parms.Length; i += 2)
                {
                    switch (Int32.Parse(parms[i]))
                    {
                    case (int)HttpRequestConstants.HTTP_METHOD:

                        htc.HttpMethod = parms[i + 1];
                        break;

                    case (int)HttpRequestConstants.HTTP_MIMETYPE:

                        htc.HttpMIMEType = parms[i + 1];
                        break;

                    case (int)HttpRequestConstants.HTTP_BODY_MAXLENGTH:

                        BODY_MAXLENGTH = int.Parse(parms[i + 1]);
                        break;

                    case (int)HttpRequestConstants.HTTP_VERIFY_CERT:

                        htc.HttpVerifyCert = (int.Parse(parms[i + 1]) != 0);
                        break;
                    }
                }
            }

            bool ShouldProcess = true;

            HTTPMax r = null;

            if (!m_numberOfPrimHTTPRequests.TryGetValue(primID, out r))
            {
                r = new HTTPMax();
            }

            if (DateTime.Now.AddSeconds(1).Ticks > r.LastTicks)
            {
                r.Number = 0;
            }

            if (r.Number++ > MaxNumberOfHTTPRequestsPerSecond)
            {
                ShouldProcess = false; //Too many for this prim, return status 499
                htc.Status    = (int)OSHttpStatusCode.ClientErrorJoker;
                htc.Finished  = true;
            }

            htc.PrimID          = primID;
            htc.ItemID          = itemID;
            htc.Url             = url;
            htc.MaxLength       = BODY_MAXLENGTH;
            htc.ReqID           = reqID;
            htc.HttpTimeout     = httpTimeout;
            htc.OutboundBody    = body;
            htc.ResponseHeaders = headers;
            htc.proxyurl        = m_proxyurl;
            htc.proxyexcepts    = m_proxyexcepts;

            lock (HttpListLock)
            {
                if (m_pendingRequests.ContainsKey(itemID))
                {
                    m_pendingRequests[itemID].Add(htc);
                }
                else
                {
                    m_reqID2itemID.Add(reqID, itemID);
                    m_pendingRequests.Add(itemID, new List <HttpRequestClass> {
                        htc
                    });
                }
            }

            if (ShouldProcess)
            {
                htc.Process();
            }
            //Make sure that the cmd handler thread is running
            m_scriptModule.PokeThreads(itemID);

            return(reqID);
        }
        public UUID StartHttpRequest(UUID primID, UUID itemID, string url, List<string> parameters,
                                     Dictionary<string, string> headers, string body)
        {
            UUID reqID = UUID.Random();
            HttpRequestClass htc = new HttpRequestClass();

            // Partial implementation: support for parameter flags needed
            //   see http://wiki.secondlife.com/wiki/LlHTTPRequest
            //
            // Parameters are expected in {key, value, ... , key, value}

            int BODY_MAXLENGTH = DEFAULT_BODY_MAXLENGTH;

            if (parameters != null)
            {
                string[] parms = parameters.ToArray();
                for (int i = 0; i < parms.Length; i += 2)
                {
                    switch (Int32.Parse(parms[i]))
                    {
                        case (int) HttpRequestConstants.HTTP_METHOD:

                            htc.HttpMethod = parms[i + 1];
                            break;

                        case (int) HttpRequestConstants.HTTP_MIMETYPE:

                            htc.HttpMIMEType = parms[i + 1];
                            break;

                        case (int) HttpRequestConstants.HTTP_BODY_MAXLENGTH:

                            BODY_MAXLENGTH = int.Parse(parms[i + 1]);
                            break;

                        case (int) HttpRequestConstants.HTTP_VERIFY_CERT:

                            htc.HttpVerifyCert = (int.Parse(parms[i + 1]) != 0);
                            break;

                        case (int) HttpRequestConstants.HTTP_VERBOSE_THROTTLE:

                            htc.VerbroseThrottle = (int.Parse(parms[i + 1]) != 0);
                            break;

                        case (int) HttpRequestConstants.HTTP_PRAGMA_NO_CACHE:

                            if (int.Parse(parms[i + 1]) != 0)
                            {
                                headers["Pragma"] = "no-cache";
                            }
                            break;

                        case (int) HttpRequestConstants.HTTP_CUSTOM_HEADER:

                            string name = parms[i + 1];
                            string value = parms[i + 2];
                            i++; //Move forward one, since we pulled out 3 instead of 2
                            headers[name] = value;
                            break;
                    }
                }
            }

            bool ShouldProcess = true;

            HTTPMax r = null;
            if (!m_numberOfPrimHTTPRequests.TryGetValue(primID, out r))
                r = new HTTPMax();

            if (DateTime.Now.AddSeconds(1).Ticks > r.LastTicks)
                r.Number = 0;

            if (r.Number++ > MaxNumberOfHTTPRequestsPerSecond)
            {
                ShouldProcess = false; //Too many for this prim, return status 499
                htc.Status = (int) 499;
                htc.Finished = true;
            }

            htc.PrimID = primID;
            htc.ItemID = itemID;
            htc.Url = url;
            htc.MaxLength = BODY_MAXLENGTH;
            htc.ReqID = reqID;
            htc.HttpTimeout = httpTimeout;
            htc.OutboundBody = body;
            htc.ResponseHeaders = headers;
            htc.proxyurl = m_proxyurl;
            htc.proxyexcepts = m_proxyexcepts;

            lock (HttpListLock)
            {
                if (m_pendingRequests.ContainsKey(itemID))
                    m_pendingRequests[itemID].Add(htc);
                else
                {
                    m_reqID2itemID.Add(reqID, itemID);
                    m_pendingRequests.Add(itemID, new List<HttpRequestClass> {htc});
                }
            }

            if (ShouldProcess)
                htc.Process();
            //Make sure that the cmd handler thread is running
            m_scriptModule.PokeThreads(itemID);

            return reqID;
        }